Hello. How can I count the number of objects with a certain tag that are in a scene at the current time(I eventually want to set up something like "if there are > 20 objects with the tag "Enemy" do...")?Thanks
2 Answers
2Hi!
var gos : GameObject[];
gos = GameObject.FindGameObjectsWithTag("Enemy");
if(gos.length > 20)
{
// Do Something
}
Hope it helps!
1 Like
Length needs to have a capital L too. I don't know if it was different back in 2010, when this response was made though.
– SilverFang180882Or if you want to do this in just one line:
if(GameObject.FindGameObjectsWithTag("Enemy").Length > 20) {
// Do something
}
See my answer at http://answers.unity3d.com/questions/29314/destroy-all-objects-with-a-certain-tag.
– j_y_k