Advanced Wave Spawner

Hi, I made a simple wave spawner that spawns one type of enemies:

void Update () {
		
		if (player.transform.position.y < -50) {
			
			waveIndex = 0;
			countdown = 15f;
		}

		if (enemiesAlive > 0) {

			return;
		}

		if (countdown <= 0f) {

			StartCoroutine (spawnWave());
			countdown = deltaWaves;

			return;
		}


		countdown -= Time.deltaTime;
		countdown = Mathf.Clamp (countdown, 0f, Mathf.Infinity);

	}

	IEnumerator spawnWave() {

		waveIndex++;

		for (int i = 0; i < waveIndex; i++) {

			spawnEnemy ();
			yield return new WaitForSeconds (0.5f);
		}

	}

	void spawnEnemy() {

		spawnIndex = Random.Range (0, Spawnpoints.points.Length - 1);

		Instantiate (enemy, Spawnpoints.points[spawnIndex].transform.position, Quaternion.identity);

		enemiesAlive++;
	}
}

Basically, I want to edit the code above to make it support multiple enemy types in a single wave. How should I do this?

Thanks,

~Higgsboson728

(Please do not link me to the wiki)

First, you want the spawnEnemy method to be passed an enemy parameter :

void spawnEnemy (GameObject enemy)
{
    spawnIndex = Random.Range (0, Spawnpoints.points.Length - 1);
    Instantiate (enemy, Spawnpoints.points[spawnIndex].transform.position, Quaternion.identity);
    enemiesAlive++;
}

Then, you want the spawnWave method to tap into a table of enemies with some cycling or random indexing.

public List<GameObject> enemies; // a list of game objects that'll store the enemies references
IEnumerator spawnWave()
{
    waveIndex++;
    int index;
    for (int i = 0; i < waveIndex; i++)
    {
        index = Random.Range (0, enemies.Count); // using random here
        //index = (index >= enemies.Count-1) ? 0 : index+1; // or using cycling
        spawnEnemy (enemies[index]);
        yield return new WaitForSeconds (0.5f);
    }
}