I have a very small city for my game. The idea is that the player shoots the buildings in the city and destroys them. But, as I said, the game board is very small, and to destroy all the buildings takes mere seconds. I’d like to make it possible to destroy buildings, and make them all re-appear at the push of a button. As of right now, the buildings are not truly destroyed, but rather are deactivated, using
gameObject.SetActive(false);
In a separate script, I have
if(Input.GetKeyDown(Keycode.Return))
{
buildings.SetActive(true);
}
where “buildings” is a public gameobject. In the editor, the gameobject “buildings” is assigned as an empty gameobject containing the other buildings in my scene as children.
This solution as I have it doesn’t work. I figure it is because I am disabling the buildings individually, but enabling the parent object, leaving the children untouched. My question is this. What code do I need to use (C# please!) to SetActive(true)
for all of the children of the “buildings” gameobject?
I suppose I could simply assign all of the individual buildings as their own gameobject in the script, and activate them as such
building1.Setactive(true);
building2.Setactive(true);
building3.Setactive(true);
.....
but that is kind of exhausting, especially when I expand my map to include more buildings. There must be a way to do this all at once, or at least a way more efficient than doing them all individually. Any help appreciated.