I fixed it awhile ago by accident lol

 private void TimerListen()
    {
       
       
        
        if (isItDone)
        {
            var spawners = FindObjectsOfType<AttackerSpawner>();
            foreach (AttackerSpawner spawner in spawners)
            {
                spawner.StopSpawning();
            }
            CheckForEnemies();
        }
        else { return; }
    }
    private void CheckForEnemies()
    {
      
        if(listOfEnemies <= 0)
        {
            StartCoroutine("WinEvent");   
        }
        else { return; }
    }
    IEnumerator WinEvent()
    {
        winBanner.SetActive(true);
        yield return new WaitForSeconds(waitTime);
        sceneLoader.LoadNextScene();
        yield break;
    }

I made it so that the bool that activates the foreach loop also uses the check for enemies method and starts a coroutine when enemies are 0. This can only happen when the fox timer is 0 so it won’t happen before then.

This is good yes?

It looks fine to me.

One point to make, you don’t need the following line:
yield break;

Another point: I’d switch your StartCoroutine line to:
StartCoroutine(WinEvent());

It’s a minor change, but this way, if you use a change method name function in the editor, it’ll also change this one too. As a string, you’d need to manually change it each time.

1 Like

Oh yeah I forgot haha. Rick had us on string names so i forgot how to do it the normal way. Also I forget why we needed to use yield break and I assumed it was to end the coroutine but I guess I missused it. remind what it’s for again?

It’s basically “return” for a coroutine. It isn’t needed at the end as it’ll be returning anyway.

1 Like

Privacy & Terms