- Home /
Question by
ShinyTaco · Apr 02, 2013 at 04:38 AM ·
gameobjectserverfalse
How to Set GameObject.FindGameObjectsWithTag to SetActive(false)?
Hey guys,
I've been searching around and haven't found anything. Any help is really appreciated. What is the correct syntax for hiding a gameObject with a tag? I know about gameObject.SetActive (false); but do not know how to do it with a tag.
Here's what I have:
GameObject.FindGameObjectsWithTag("myTag");
I don't know where or how to set that SetActive(false);
Any help or links is greatly appreciated.
Thanks!
Comment
Best Answer
Answer by ByteSheep · Apr 02, 2013 at 05:02 AM
This should work:
var gos : GameObject[];
//get all the objects with the tag "myTag"
gos = GameObject.FindGameObjectsWithTag("myTag");
//loop through the returned array of game objects and set each to active false
for (var go : GameObject in gos) {
go.SetActive(false);
}
http://docs.unity3d.com/Documentation/ScriptReference/GameObject.FindGameObjectsWithTag.html
Answer by weXem · Apr 02, 2013 at 06:00 AM
GameObject.FindGameObjectWithTag("myTag").SetActive(false);
Your answer
