After the ObjectPool script and lesson my enemies stop moving on path. Have tripled checked the code compare to instructor but i cant find the issue. I got Enemy Health and Enemy Mover scripts on the Enemy Prefab, i got Objectpool script on the Objectpool gameobject.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ObjectPool : MonoBehaviour
{
[SerializeField] GameObject enemyPrefab;
[SerializeField] float spawnTimer = 1f;
[SerializeField] int poolSize = 5;
GameObject[] pool;
void Awake()
{
PopulatePool();
}
void Start()
{
StartCoroutine(SpawnEnemy());
}
void PopulatePool()
{
pool = new GameObject[poolSize];
for (int i = 0; i < pool.Length; i++)
{
pool[i] = Instantiate(enemyPrefab , transform);
pool[i].SetActive(false);
}
}
void EnableObjectInPool()
{
for (int i = 0; i < pool.Length; i++)
{
if(pool[i].activeInHierarchy == false)
{
pool[i].SetActive(true);
return;
}
}
}
IEnumerator SpawnEnemy()
{
while(true)
{
EnableObjectInPool();
yield return new WaitForSeconds(spawnTimer);
}
}
}