Here’s an alternative solution I made for the enable-object-in-pool method. We iterate through the pool with the foreach loop, using Linq to only fetch the objects in the pool that are not active in the hierarchy. We then set them active, and wait before spawning the next. Once all of them are spawned, we then do a further wait-for-seconds so that 1) the game doesn’t freeze, and 2) so there is an adjustable time gap between the enemy reaching the end of the path and the new wave spawning.
private IEnumerator EnableObjectInPool()
{
while (true)
{
foreach (var enemy in EnemyPool.Where(x => !x.activeInHierarchy))
{
enemy.SetActive(true);
yield return new WaitForSeconds(spawnTimer);
}
yield return new WaitForSeconds(waveTimer);
}
}