Basically, my question is the same as the title.
Does any one know?
Basically, my question is the same as the title.
Does any one know?
GameObject[] gameObjects = GameObject.FindGameObjectsWithTag("tag name")
Thanks for the reply, but I’m a bit confused about how to add it correctly.
What I am trying to do is located right here.
This is my code. I’m not sure what is wrong with it, but it keeps telling me I have an error:
var all : GameObject = GameObject.FindGameObjectsWithTag("alien");
all.transform.Translate(0, moveV * Time.deltaTime, 0);
You should have a look in the documentation, Unity - Scripting API: GameObject.FindGameObjectsWithTag
GameObject.FindGameObjectWithTag returns a list of all GameObjects with the tag you specify. You then have to iterate through that list to access each and every one of those objects.
I don’t work with javascript myself, but I think the code you’re looking for is something along the lines of
var all : GameObject[] = GameObject.FindGameObjectsWithTag("alien");
for (var alien : GameObject in all)
alien.transform.Translate(0, moveV * Time.deltaTime, 0);
So rather than reference objects directly you always have to work with arrays?
The documentation for FindGameObjectsWithTag specifically says it returns a GameObject array. So in this case, yes.
You can always make a variable equal one of the objects in that array though. So, no, you do do not always have to work with arrays.