- Home /
Is there a way to count how many tagged objects are in a scene?
Hi im pretty awful at coding and I have been looking around tutorials, and i cant find a way to do this. Im trying to track the number of NPC's In the scene, they do have the ability to get destroyed, so it needs to have a "live" update. But i have no idea where to start on this, if anyone could point out a tutorial i would be really happy.
Answer by woodoo · Jan 14, 2014 at 02:58 PM
GameObject.FindGameObjectsWithTag(string tag)
returns an array of GameObject
(all game objects found with the tag specified), so you can use it and get the number of objects with the Length
property of the array.
As the snippet below:
GameObject[] npcs = GameObject.FindGameObjectsWithTag("NPC");
int numberOfNPCS = npcs.Length;
Your answer
Follow this Question
Related Questions
Building my own benchmarking program 1 Answer
How to destroy a gameobject when I collide with it? 2 Answers
How can I detect the number of enemies? 2 Answers
Passing variables from client to server 1 Answer
How to Reduce the lag? 3 Answers