- Home /
Question by
IG88Droid · Mar 23, 2018 at 06:52 PM ·
gameobjectsetactivegameobject.find
How to activate all inactive objects?
I want to be able to reset my level in the game I'm working on. To do this, I want to be able to find the inactive gameobjects and re-activate them. Is there any way I could do this? If it helps, the inactive gameobjects all share the same tag and a prefab as well.
Comment
Best Answer
Answer by rheredia · Mar 23, 2018 at 07:04 PM
Search for gameobjects and store them in an array. Then pass through that array and activate them.
public void activateObjects() {
GameObject[] gameObjects = GameObject.FindGameObjectsWithTag("TAGNAME");
foreach (GameObject go in gameObjects)
{
if (!go.activeInHierarchy)
{
go.SetActive(true);
}
}
}