How to find all GameObjects in Hierarchy by name and put them in an Array[] ? (C#)
I'm trying to make an Array[] of GameObjects of a Specific Name, How do I find them by Name then put them in an Array?
thanks in advance.
I only found unswers in java.
Answer by xxmariofer · Mar 23, 2019 at 10:20 PM
you can not find all the objects called the same, but you can give a tag to all those gameobjects and use this line of code, just remmember to tag them the same
GameObject[] yourArray = GameObject.FindGameObjectsWithTag("Tag");
is it not possible with findgameobjectwithtype or something like that im not really familiar with unity
With the method i posted you could, for finding by name there uis only the gameobject.find option
GameObject[] yourArray = GameObject.FindGameObjectsWithTag("Tag"); would with find all the objects or one? it seem like it will only find one
FindGameObjectsWithTag finds all FindGameObjectWithTag finds one (make sure you are using the plural one)