Trying to spawn waves

I’m trying to get waves of enemies to spawn around my character. So far I am not having amy issues with the spawning, but I am having some trouble with the logic for getting things to wait before starting up the next wave.

I am looking to add in a 3, 2, 1, counter into the game as well, just before each wave. I set up the counter as an animation, and on the last frame call a script that will set a bool value (isCountDownDone) to true. This is so far working perfectly and I have no issues.

My problem comes when I try to put it all together. I have the countdown animation play, and have logic set to work with that, but I think I have the whole thing set up wrong but I don’t know why.

IEnumerator Spawn ()
{
while (true)
{
if (isCountDownDone == true)
{
if (aliveAliens == 0)
{
StartCoroutine (SpawnStuff ())
}
yield return new WaitForSeconds (waveWait)
}

I also need to restart the countdown animation when the waves reset, something I have not yet looked in to so if any help on that can also be given that would be great!

First of all, your code is unreadable. You should copy it from an editor:

    IEnumerator Spawn()
    {
        while (true)
        {
            if (isCountDownDone == true  && aliveAliens == 0)//maybe this should be an "or"
            {
                    StartCoroutine(SpawnStuff());
                   isCountDownDone = false;//you only need to call this once until all aliens are dead
             }
       
            yield return new WaitForSeconds(waveWait);
        }
    }

That should do the trick, thanks!

Ugh, I wish I could copy it all directly. My laptop wifi doesn’t work so I’m stuck doing my forum stuff all on a phone :confused:

Last small question, which I’m sure I’ll find if I just google it but I’ll ask anyway, how do I play a specific animation? Its a 2d sprite animation so I’m assuming its not that hard

You might need a tutorial for that. Normally you load a sprite sheet and then use mecanim. Just do a search for unity 2d animation.