// Use this for initialization void Start() { // Network manager _networkManagerGO = GameObject.FindGameObjectWithTag("NetworkManager"); // All the background cubes _background = GameObject.FindGameObjectsWithTag("Background"); // NetworkController handles the communication between clients and the host. For single player games // the SingleController is used instead with similar methods only without the Rpc and Cmd calls _networkController = NetController.GetComponent <NetworkController>(); _networkManager = _networkManagerGO.GetComponent <NetworkManager>(); Requested = new Dictionary <string, float>(); _gameMode = new GameObject[0]; Selected = -1; StartCounter = -1; _oldTime = 0.0f; _storeLoaded = false; Started = false; Chosen = false; _running = false; LoggedIn = false; }
//Clear data if not connected to a server or when you quit the game public void Clear() { Selected = -1; Chosen = false; _storeLoaded = false; // Reset the game mode sprites _gameMode = new GameObject[0]; // Reset the score menu SharedScore.GetComponent <PlaceController>().Reset(); SharedScore.SetActive(false); // Hide all the sprites IGS.SetActive(false); Countdown[0].SetActive(false); Countdown[1].SetActive(false); Countdown[2].SetActive(false); Wait.SetActive(false); Host.SetActive(false); Tab.SetActive(false); foreach (Transform child in Dots.transform) { child.gameObject.SetActive(false); } foreach (Transform t in Ability.GetComponentsInChildren <Transform>()) { t.GetComponent <SpriteRenderer>().enabled = false; } // destroy the mode selectors. They will automatically delete themselves anyway but there is a delay GameObject[] modes = GameObject.FindGameObjectsWithTag("Mode"); foreach (GameObject m in modes) { Destroy(m); } // Reset the dodgeball generators foreach (GameObject DBG in DBGS) { DBG.GetComponent <DBGenerator>().Counter = 0; DBG.GetComponent <DBGenerator>().InGame = false; } // Destroy all the dodgeballs foreach (GameObject b in GameObject.FindGameObjectsWithTag("DodgeBall")) { Destroy(b); } // Destroy all the players in a single player game. Automatically done // in online games if (SinglePlayer) { foreach (GameObject p in GameObject.FindGameObjectsWithTag("Player")) { Destroy(p); } } // Reset variables SinglePlayer = false; _running = false; Started = false; StartCounter = -1; // Go to the home page GetComponent <TitleScreenController>().Home(); // Reset the network controller if (_networkController.Client && !_networkController.Server) { _networkController.Client = false; _networkController.Server = false; _networkController.Players = 0; _networkManager.StopClient(); } // If you are the server host tell all the clients to disconnect if (_networkController.Server) { NetController.GetComponent <NetworkController>().RpcDisconnect(GameObject.FindGameObjectsWithTag("Player").Length); } // Hide all end screen sprites GetComponent <WinnerScreen>().Clear(); }