How can I reference only the gameobject of the one selected instantiated prefab and not every version of that gameobjects in all the other prefabs of the same kind ?

I’ve been stuck for a while trying to work out how to get this working so would really appreciate any help I can get!


I have a set of spawners in my project. Each spawner instantiates a randomely selected prefab when the game begins. Within each prefab is an object which has a couple of different layers which I am trying to allow the player to toggle through using arrow keys - only on the object they have selected.


The problem I keep running into is that these layers toggle through on all of the instantiated prefabs. I’m not sure what to do because I believe I need to attach the layer gameobjects on a script inside the prefab. Currently they’re attached to a script which simply uses SetActive as the player scrolls switches layers.


How can I reference only the layers of the one selected instantiated prefab and not all the other prefabs of the same kind in the scene?


Hello.

When trying to “find” one object among all other “identical” objects, ypu need something that makes the object different. It can be a position, a variable in a script, a collision, a tag, a layer… something.

and do something like :

from all objects like this, do a foreach iteration
inside foreach, if the iteration object has the special property, assign to a gameobject variable

Was this your question?
if not, give more info or something because i didnt understood you :smiley: