x


Count the number of objects with a certain tag?

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

more ▼

asked Nov 28 '10 at 10:18 PM

Tyler 2 gravatar image

Tyler 2
1.1k 211 246 264

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Hi!

var gos : GameObject[];
gos = GameObject.FindGameObjectsWithTag("Enemy");
if(gos.length > 20)
{
  // Do Something
}

Hope it helps!

more ▼

answered Nov 29 '10 at 12:54 PM

TheokieZA gravatar image

TheokieZA
103 5 7 14

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x323
x323
x77

asked: Nov 28 '10 at 10:18 PM

Seen: 4516 times

Last Updated: Nov 28 '10 at 10:18 PM