Find and store gameObjects in a array

How i can find all gameObject with a certian tag in the scene and store them in a array?

2 Answers

2

One line:

GameObject[] objects = GameObject.FindGameObjectsWithTag("myTag");

Note: Code is C#

http://unity3d.com/support/documentation/ScriptReference/GameObject.FindGameObjectsWithTag.html

Going to sound stupid, but what's the equivilent of this line in Javascript? guessing it's var object : GameObject[] = GameObject.FindGAmeObjectsWithTag("MyTag"); but didn't see an exact reference for it when it came to arrays...

–

var objects : GameObject;
function Start()
{
objects = GameObject.FindGameObjectsWithTag(“Tag”);
}