diff --git a/Assets/Scripts/Environment/BoulderSpawn.cs b/Assets/Scripts/Environment/BoulderSpawn.cs index 1f3b61c..9a9079c 100644 --- a/Assets/Scripts/Environment/BoulderSpawn.cs +++ b/Assets/Scripts/Environment/BoulderSpawn.cs @@ -6,31 +6,30 @@ using UnityEngine; public class BoulderSpawn : NetworkBehaviour { + //Variables to be customized as needed in engine [SerializeField] private float RespawnTimer = 10.0f; [SerializeField] private float InitialSpawnDelay = 0.0f; - private float currentTime = 0.0f; - [SerializeField] private float boulderScaleMultiplier = 1.0f; - - [SerializeField] private Vector3 spawnForce; - [SerializeField] private Vector3 SpawnLocation; - [SerializeField] private Transform BoulderPrefab; + + //Variables for managing cleanup and spawning + private float currentTime = 0.0f; private GameObject boulderInScene; - // Start is called before the first frame update void Start() { - if (IsHost) + if (IsHost) //On startup call spawn RPC as host { SpawnBoulderServerRPC(); } } [ServerRpc(RequireOwnership = false)] - private void SpawnBoulderServerRPC() { + private void SpawnBoulderServerRPC() + { + //Intantiate a boulder, rescale it, then spawn it on all clients, then start its despawn countdown boulderInScene = Instantiate(BoulderPrefab, SpawnLocation, Quaternion.identity).gameObject; boulderInScene.transform.localScale *= boulderScaleMultiplier; boulderInScene.GetComponent().Spawn(null, true); @@ -39,8 +38,10 @@ public class BoulderSpawn : NetworkBehaviour private void FixedUpdate() { + //Clients disregard this update if (!IsHost) { return; } + //Host updates the time for respawning boulder then recalls the spawn RPC currentTime += Time.fixedDeltaTime; if (currentTime >= RespawnTimer + InitialSpawnDelay) {