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

Counting active objects in a list

$
0
0
Utilizing the idea of object pooling, and storing said objects in a list. As seen in here: [Object Pooling][1] I would like to run a check on that list to see if there are any objects active. I know you can utilize GameObject.activeInHierarchy on singular objects such as this Spawn() code: List objectQueue; void Spawn () { for (int i = 0; i < objectQueue.Count; i++) { if(!objectQueue[i].activeInHierarchy) { DetermineSpawnLocation(objectQueue[i]); //Decide where to spawn objectQueue[i].SetActive(true); //object spawning break; } } } I would like to do this check in a separate function as this Spawn code is called after some checks are made, and one of the checks I need to add is 'if there are any active shapes, wait for the count to be 0' (no active shapes in scene) before continuing. I was considering a foreach or for loop and manually counting active objects, but it seems there should be a better way. If this question has be answered before please link it and reprimand me properly. Apologies if the answer is crazy simple. **TL;DR: How to count number of active objects within a list in simplest way possible.** [1]: http://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/object-pooling

Viewing all articles
Browse latest Browse all 187

Trending Articles



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