Quantcast
Channel: Questions in topic: "count"
Viewing all articles
Browse latest Browse all 187

Why only one element is displayed by count when the list has 5 elements in it?,Why Count method is showing only 1 element if the List has 5 elements in it?

$
0
0
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); } }

Viewing all articles
Browse latest Browse all 187

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>