IEnumerator DrawBeforeText(TutorialWave w) { int delay = (int)w.delayBeforeWave; this.countDownText.enabled = true; for (int i = delay - 1; i > -1; i--) { this.countDownText.text = i.ToString(); yield return(new WaitForSeconds(1)); } this.countDownText.enabled = false; }
IEnumerator SpawnLoop() { foreach (TutorialWave W in waves) { if (currentWaveIndex >= waves.Count) { break; } // update current wave m_CurrentWave = W; GameManager.Instance.player_totalCurrency = m_CurrentWave.startingMoney; foreach (MessageData messageData in W.Messages) { this.ShowMessage(messageData); // do nothing while the popup message is up while (this.PopupMessage.activeSelf) { yield return(null); } } UI_WeaponRadial.buttonDisabled["N"] = !W.weaponRadial.N; UI_WeaponRadial.buttonDisabled["S"] = !W.weaponRadial.S; UI_WeaponRadial.buttonDisabled["E"] = !W.weaponRadial.E; UI_WeaponRadial.buttonDisabled["W"] = !W.weaponRadial.W; UI_UpgradeRadial.buttonDisabled["E"] = !W.upgradeRadial.E; UI_UpgradeRadial.buttonDisabled["W"] = !W.upgradeRadial.W; if (W.clearTurrets) { BuildZone[] bzs = FindObjectsOfType <BuildZone>(); foreach (BuildZone bz in bzs) { bz.Clear(); } } // do nothing while the popup message is up while (this.PopupMessage.activeSelf) { yield return(null); } //Display countdown to wave start if (W.delayBeforeWave > 0) { StartCoroutine(DrawBeforeText(W)); yield return(new WaitForSeconds(W.delayBeforeWave)); } this.countDownText.enabled = false; //Spawners start isWaveActive = true; ZombieSpawner[] spawns = FindObjectsOfType <ZombieSpawner>(); foreach (ZombieSpawner zs in spawns) { //possibly add a yield return here StartCoroutine(zs.BeginSpawnWave(currentWaveIndex)); } //allow 1 second for spawners to start yield return(new WaitForSeconds(1)); // wave is not over until all zombies are dead while (isWaveActive || FindObjectsOfType <Zombie>().Length > 0) { yield return(new WaitForSeconds(0.1f)); } // A wave has complete currentWaveIndex++; yield return(null); // prevents crash if all delays are 0 } if (PlayerBase_Stats.Instance.currentHitPoints > 0) { ShowMessage(this.SuccessMessage); // do nothing while the popup message is up while (this.PopupMessage.activeSelf) { yield return(null); } GameManager.Instance.GetComponent <AudioSource>().clip = GameManager.Instance.menuMusic; GameManager.Instance.GetComponent <AudioSource>().Play(); SceneManager.LoadScene("SelectLevel"); yield return(null); // prevents crash if all delays are 0 } }