IEnumerator SpawnWave(Wave wave) { List <GameObject> enemies = wave.enemies; float delay = wave.delay; int enemyIndex = 0; do { int spawnIndex = Random.Range(0, spawnPoints.Count); Vector2 spawnPoint = spawnPoints[spawnIndex]; if (wave.isBoss) { spawnPoint = centrePos; } spawnDoors[spawnIndex].SetTrigger("Open"); GameObject enemy = Instantiate(enemies[enemyIndex], spawnPoint, Quaternion.identity); waveHandler.AddEnemy(enemy); EnemyStats enemyScript = enemy.GetComponent <EnemyStats>(); ColorInfo color = colorMats[Random.Range(0, colorMats.Length)]; enemyScript.material = color.mat; enemyScript.tag = color.color; enemyIndex++; yield return(new WaitForSeconds(delay / 2)); spawnDoors[spawnIndex].SetTrigger("Close"); yield return(new WaitForSeconds(delay - delay / 3)); } while (enemyIndex < enemies.Count); }