- Home /
How to get all instances of an object in the scen
Hello.
I am trying to find and store in array the instances of an object, that have been put in the scene.
Let's say that i have a prefab with sphere inside... I drag\drop 5 times that sphere to a different places on the scene. Is there a way to get the positions of all these 5 instances, by JavaScript, so i can use them later for certain pusposes? Like some way to get access to all of the instances, that one prefab (or object) have on the hierarhy\scene.
The JScript, that i'm trying to access them is attached to another gameObject.
Thank you :)
Answer by hvilela · Aug 14, 2012 at 03:53 PM
I recommend you to create a list to save the reference for each object you spawn. Otherwise, to find it all I recommend you to create a tag and use GameObject.FindGameObjectsWithTag("yourTagName").
Answer by instruct9r · Aug 14, 2012 at 07:49 PM
cool, thanks will try the the Find with TAG...
But if there are 5 objects in the scene, assigned to that TAG, is it going to return them as array? Will i be able to control each of them separately?
Thanks
Your answer
Follow this Question
Related Questions
Access manually instantiated object 1 Answer
Prefab not loading in data from Inspector 1 Answer
Changing the Variables of An Instanced Script 2 Answers
Can't edit built-in array through script unless viewed in Inspector 1 Answer
How to refer to a collision between clones of the same prefab? C# 1 Answer