// Update is called once per frame void Update() { //Check to see if level Ended (main base blown up) GameObject Building = GameObject.FindWithTag("MainBuilding"); GameObject Building2 = GameObject.FindWithTag("MainBuilding2"); if (Building == null || Building2 == null) { if (TowerUpgrader.GetLevel() == 5 || Building == null) { //Start the countdown to reload StartCoroutine(Wait()); //Possible reload display message. //If we want to destory enemies when level ends /* GameObject[] enemiesDestory = GameObject.FindGameObjectsWithTag("Enemy"); * * for (int i = 0; i < enemiesDestory.Length; i++) { * Destroy (enemiesDestory [i]); * } * */ //Blow up buildings when level ends GameObject[] buildingsDestory = GameObject.FindGameObjectsWithTag("Building"); for (int i = 0; i < buildingsDestory.Length; i++) { GameObject temp = buildingsDestory [i]; BuildingHealth sn = temp.gameObject.GetComponent <BuildingHealth> (); if (sn != null) { sn.goDestroy(); } //Destroy (buildingsDestory [i]); } } } GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemy"); int enemiesLeft = enemies.Length; if (enemiesLeft == 0) { //print ("Triggered"); if (waveCount <= 0 && gameController != null) { FadeIn.ChangeToWin(1); FadeIn.BeginFade(1); //FadeIn.ChangeToWin (0); if (SceneManager.GetActiveScene().name == "level1") { gameController.SetScore(ScoreManager.score); gameController.SetCash(EnergyManager.energy); TowerUpgrader.SetLevel(2); StartCoroutine(Wait2()); //SceneManager.LoadScene("Upgrades"); } else if (SceneManager.GetActiveScene().name == "level2") { gameController.SetScore(ScoreManager.score); gameController.SetCash(EnergyManager.energy); TowerUpgrader.SetLevel(3); StartCoroutine(Wait2()); //SceneManager.LoadScene("Upgrades"); } else if (SceneManager.GetActiveScene().name == "level3") { gameController.SetScore(ScoreManager.score); gameController.SetCash(EnergyManager.energy); TowerUpgrader.SetLevel(4); StartCoroutine(Wait2()); //SceneManager.LoadScene("Upgrades"); } else if (SceneManager.GetActiveScene().name == "level4") { gameController.SetScore(ScoreManager.score); gameController.SetCash(EnergyManager.energy); TowerUpgrader.SetLevel(5); StartCoroutine(Wait2()); //SceneManager.LoadScene("Upgrades"); } else if (SceneManager.GetActiveScene().name == "level5") { gameController.SetScore(ScoreManager.score); gameController.SetCash(EnergyManager.energy); TowerUpgrader.SetLevel(1); StartCoroutine(Wait2()); //SceneManager.LoadScene("Upgrades"); } } // do something } }