I have two versions of the same code. One that i did myself and the other i got by following the course. Can someone please explain the difference because both codes are working perfectly fine. I just want to know if i would get any problems in the future with my code
MINE:
IEnumerator activateEnemy()
{
while (true)
{
for(int i = 0; i < pool.Length; i++)
{
pool[i].SetActive(true);
yield return new WaitForSeconds(timePeriod);
}
}
}
COURSE:
void enablePoolObject()
{
for (int i = 0; i < pool.Length; i++)
{
if (pool[i].activeInHierarchy == false)
{
pool[i].SetActive(true);
return;
}
}
}
IEnumerator activateEnemy()
{
while (true)
{
enablePoolObject();
yield return new WaitForSeconds(timePeriod);
}
}
What this code does is it enables the enemy from the object pool so that it can do the stuff its supposed to do. The activation is based on a coroutine that has a period defined by ‘timePeriod’