IEnumerator EnemySpawner() { while (true) { for (int i = 0; i < enemySpawnCount; i++) { if (isGameOver) { UIHCSs.waveCountText.enabled = false; isGameOver = false; yield return(new WaitForSeconds(4f)); reStartText.enabled = true; isGameOver = true; yield return(new WaitForSeconds(4f)); music.AfterGameOverPlay(); break; } GameObject enemy = enemySpawn [Random.Range(0, enemySpawn.Length)]; Vector3 enemySpawnPosition = new Vector3(spawnValues.x, Random.Range(-2, 4), spawnValues.z); Quaternion enemyRotation = Quaternion.identity; Instantiate(enemy, enemySpawnPosition, enemyRotation); yield return(new WaitForSeconds(1.3f)); } if (waveCount == 2 || waveCount == 5 || waveCount == 8) { Vector3 plrBltPwrPos = new Vector3(spawnValues.x, Random.Range(-2, 4), spawnValues.z); Instantiate(PlrBltPower, plrBltPwrPos, Quaternion.identity); } if (isGameOver) { UIHCSs.waveCountText.enabled = false; isGameOver = false; yield return(new WaitForSeconds(4f)); reStartText.enabled = true; isGameOver = true; yield return(new WaitForSeconds(4f)); music.AfterGameOverPlay(); break; } UIHCSs.WaveCount(enemySpawnCount); waveCount += 1; yield return(new WaitForSeconds(3f)); UIHCSs.waveCountText.enabled = false; enemySpawnCount += 5; } }