ForEach loop instead of For loop?

In the last section of the Realm Rush course of the Object Pool tutorial, I used a foreach loop instead of the recommended for loop.
I just wanted to check if someone could tell me if this is correct?
Thanks!

IEnumerator SpawnEnemy()
    {
        while(true)
        {
            EnableObjectInPool();
            yield return new WaitForSeconds(spawnTimer);
        }
    }

void EnableObjectInPool()
    {
        foreach (GameObject objectInPool in pool)
        {
            if(!objectInPool.activeInHierarchy)
            {
                objectInPool.SetActive(true);
                return;
            }
        }
1 Like

Hi,

Did you test your idea? Does it work? If so, it’s a solution. :slight_smile:


See also:

I tested it and it was working, thanks for the words of encouragement Nina! :grinning:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms