diff --git a/Assets/Game1.unity b/Assets/Game1.unity index a1eb8cb..65ba7c3 100644 Binary files a/Assets/Game1.unity and b/Assets/Game1.unity differ diff --git a/Assets/Game2.unity b/Assets/Game2.unity index ff9dbb0..17403aa 100644 Binary files a/Assets/Game2.unity and b/Assets/Game2.unity differ diff --git a/Assets/Game3.unity b/Assets/Game3.unity index f27cbfa..586bf7c 100644 Binary files a/Assets/Game3.unity and b/Assets/Game3.unity differ diff --git a/Assets/NetworkManagerRocket.cs b/Assets/NetworkManagerRocket.cs index 2babaa9..eedad64 100644 --- a/Assets/NetworkManagerRocket.cs +++ b/Assets/NetworkManagerRocket.cs @@ -12,32 +12,40 @@ public class NetworkManagerRocket : NetworkManager private void OnLevelWasLoaded(int level) { - RockField1 = Instantiate(spawnPrefabs.Find(prefab => prefab.name == "RockField1")); - RockField2 = Instantiate(spawnPrefabs.Find(prefab => prefab.name == "RockField2")); - NetworkServer.Spawn(RockField1); - NetworkServer.Spawn(RockField2); } public override void OnStartHost() { - RockField1 = Instantiate(spawnPrefabs.Find(prefab => prefab.name == "RockField1")); - RockField2 = Instantiate(spawnPrefabs.Find(prefab => prefab.name == "RockField2")); - NetworkServer.Spawn(RockField1); - NetworkServer.Spawn(RockField2); } public override void OnStopHost() { - // destroy Rockfield - if (RockField1 != null) - NetworkServer.Destroy(RockField1); - if (RockField2 != null) - NetworkServer.Destroy(RockField2); } public static int level = 1; public int lastCount = 0; + static bool preparing = false; + + void SwitchScenes() + { + RocketSphere[] players = FindObjectsOfType(); + + for (int i = 0; i < players.Length; i++) + { + // deactivate all the ships on all clients + players[i].RpcMySetActive(false, Quaternion.identity, true); + + // spawn ships, on all clients + players[i].rpcSpawnShipDelay(); + } + + // switch to the next level + ServerChangeScene("Game" + level); + + preparing = false; + } + void Update() { if (RockSphere.count != lastCount) @@ -51,9 +59,19 @@ void Update() level = 1; } - ServerChangeScene("Game" + level); + preparing = true; + + // stop the music at the end of the level + Camera.main.transform.gameObject.GetComponent().Stop(); + + // wait 10 seconds before switching to the next level + Invoke("SwitchScenes", 10); } } - } + if (Input.GetKeyDown(KeyCode.Escape)) + { + Application.Quit(); + } + } } \ No newline at end of file diff --git a/Assets/RockField1.prefab b/Assets/RockField1.prefab index 3c3d6ab..d48bef1 100644 Binary files a/Assets/RockField1.prefab and b/Assets/RockField1.prefab differ diff --git a/Assets/RockField2.prefab b/Assets/RockField2.prefab index 5825879..c2589a0 100644 Binary files a/Assets/RockField2.prefab and b/Assets/RockField2.prefab differ diff --git a/Assets/RockSphere1.prefab b/Assets/RockSphere1.prefab index 705b1a4..93e420c 100644 Binary files a/Assets/RockSphere1.prefab and b/Assets/RockSphere1.prefab differ diff --git a/Assets/RocketSphere.cs b/Assets/RocketSphere.cs index 8b4458c..23e7c9d 100644 --- a/Assets/RocketSphere.cs +++ b/Assets/RocketSphere.cs @@ -70,13 +70,21 @@ public override void OnStartServer() RocketSphere[] players = FindObjectsOfType(); - for (int i = 0; i < players.Length; i++) + int count = 0; + for (int i = 1; i < players.Length; i++) { + count++; + if (count > 10) + { + Debug.Log("Give up finding a better color"); + break; // give up + } + // check for difference between player and chosen hue, // difference check must be small enough that we have enough colors for all players. // if max player count is increased from 4, this value should be reassessed // this could be an infinte check otherwise, might want a failsafe escape - if (Mathf.Abs(hue - players[i].hue) < 0.1f) + if ((Mathf.Abs(hue - players[i].hue) < 0.15f) && (players[i] != this)) { // generate a new hue if it is too close to this other players color hue = Random.Range(0.0f, 1.0f); @@ -86,7 +94,7 @@ public override void OnStartServer() } } - // rocket color is now set for this player until it is destroyed + // rocket color is now set for this player until it is destroyed or disconnects RocketColor = Color.HSVToRGB(hue, 1.0f, 1.0f); } @@ -150,7 +158,7 @@ private void OnLevelWasLoaded(int level) Camera.main.GetComponent().player = transform.gameObject.transform.Find("Rocket").gameObject.transform; } - void MySetActive(bool active, Quaternion rotation) + void MySetActive(bool active, Quaternion rotation, bool playhyperspace) { if (active == false) { @@ -178,21 +186,25 @@ void MySetActive(bool active, Quaternion rotation) rocket.SetActive(true); visible = true; - // play the hyperspace sound on enable + } + + if (playhyperspace == true) + { + // play the hyperspace sound hyperspaceSound.Play(); } } [ClientRpc] - void RpcMySetActive(bool active, Quaternion rotation) + public void RpcMySetActive(bool active, Quaternion rotation, bool playhyperspace) { - MySetActive(active, rotation); + MySetActive(active, rotation, playhyperspace); } [Command] - void CmdMySetActive(bool active, Quaternion rotation) + void CmdMySetActive(bool active, Quaternion rotation, bool playhyperspace) { - RpcMySetActive(active, rotation); + RpcMySetActive(active, rotation, playhyperspace); } [Client] @@ -201,14 +213,18 @@ void SpawnShip() if (!isLocalPlayer) return; // re-enable this rocket on all clients through server at the direction the user is looking at the moment - CmdMySetActive(true, Camera.main.transform.rotation); + CmdMySetActive(true, Camera.main.transform.rotation, true); + isSpawning = false; } + bool isSpawning; + [ClientRpc] - void rpcSpawnShipDelay() + public void rpcSpawnShipDelay() { if (!isLocalPlayer) return; + isSpawning = true; Invoke("SpawnShip", 5); } @@ -224,7 +240,7 @@ void OnTriggerEnter(Collider other) NetworkServer.Spawn(explosion); // deactivate the ship on all clients - RpcMySetActive(false, Quaternion.identity); + RpcMySetActive(false, Quaternion.identity, false); // spawn a new ship, do this on the local player client and it will re-enable on all clients rpcSpawnShipDelay(); diff --git a/ProjectSettings/EditorBuildSettings.asset b/ProjectSettings/EditorBuildSettings.asset index f6d2acf..aab0211 100644 Binary files a/ProjectSettings/EditorBuildSettings.asset and b/ProjectSettings/EditorBuildSettings.asset differ diff --git a/ProjectSettings/GraphicsSettings.asset b/ProjectSettings/GraphicsSettings.asset index 4794c37..9861984 100644 Binary files a/ProjectSettings/GraphicsSettings.asset and b/ProjectSettings/GraphicsSettings.asset differ diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index e5233de..261231a 100644 Binary files a/ProjectSettings/ProjectSettings.asset and b/ProjectSettings/ProjectSettings.asset differ