I made a list of 5 GameObjects and they are being displayed in the hierarchy(inactive though) and the print statement tells that it has 5 elements.
But when I call the GetPlatform method from another class and print the count of the List, it is displaying only 1 element which thereby, is returning null after one iteration.
Why is it happening so?
public class ObjectPooler : MonoBehaviour {
public GameObject prefab;
public int size;
List plat;
void Start () {
plat = new List ();
for (int i = 0; i < size; i++) {
GameObject o = (GameObject)Instantiate(prefab);
o.SetActive (false);
plat.Add (o);
}
print (plat.Count);
}
public GameObject GetPlatform() {
print (plat.Count);
if(plat.Count>0)
{
GameObject temp= plat[0];
plat.RemoveAt(0);
print ("GetPlatform called");
// temp.SetActive(true);
return temp;
}
return null;
}
public void DestroyPlatform(GameObject obj)
{
plat.Add (obj);
obj.SetActive (false);
}
}
↧