- Home /
How to find other gameObject's with same tag excluding itself
I have GameController script, which in Void Awake() checks if there's any other gameControllers with GameObject.FindGameObjectWithTag. And if there is, it destroys itself, but it keeps detecting itself, and just destroys itself.
How could I make it look for GameObjects with same tag, excluding itself?
Thanks in forward
Answer by tanoshimi · Sep 08, 2014 at 06:39 PM
Use FindGameObjectsWithTag
(with s) to return an array of all the gameobjects in the scene with that tag, and check the length of the returned array. If it's greater than one, your gameController can destroy itself.
Your answer
![](https://koobas.hobune.stream/wayback/20220613162605im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
keyboard commands to Joystik C# "Object reference not set to an instance of an object" 1 Answer
Changing a variable across multiple instances of a GameObject 1 Answer
How to fix a game objects that changes its position when viewed in game mode? 1 Answer
setTrigger() for another GameObject doesn't work 1 Answer
NullReferenceException: Object reference not set to an instance of an object 2 Answers