How do i make an enemy spawn, then spawn the next?


I need help on some script. All i need it to do is instead of randomizing what enemy it spawns i need it to spawn enemy 1 followed by enemy 2 after a delay say 5 seconds.

    public GameObject[] enemies;
    private void Start(){
    private IEnumerator SpawnHandler(){
    float spawnDelay;
    int thisEnemy;
    GameObject cachedEnemy;
    float dieTime;
    thisEnemy = Random.Range(0, 0); //random enemy
    spawnDelay = Random.Range(1f,3f); //random time, from 1-3
    dieTime = Random.Range(3f,6f);

    // Unity forum: Ive tried adding an enemy here using 'nextEnemy = Random.range....
    // But no luck it just spawns the enemy here when i specify(1,1)

    yield return new WaitForSeconds(spawnDelay); //wait that time
    cachedEnemy = (GameObject)Instantiate(enemies[thisEnemy], transform.position, transform.rotation);//spawn enemy, cache him
    StartCoroutine(Kill(dieTime, cachedEnemy));
    private IEnumerator Kill(float wait, GameObject enemy){
    yield return new WaitForSeconds(wait);

Ive added unity forum where ive triedto add code but it did’nt work.

Really hope someone knows the answer, its the last one of the last things i need to workout!


Dude, you asked this question six hours ago, and got an extensive answer for it as well.