I’ve figured out how to turn off the children of an object with a foreach loop, but now I need to turn the children of an object to inactive using a script on another gameobject (Ex: Object A sets the children of Object B inactive). I can’t just set the parent to inactive because I need scripts running on that object. I prefer C# btw. Thoughts? Ty!
Best way is to add the gameobject to script A. like this:
public GameObject objectB;
Then you can drag and drop the gamobject in the editor into that field.
and turn off children like this. (Probably how you already know)
foreach (Transform child in objectB.transform)
{
child.gameObject.SetActive(false);
}
However, instead of public I would do a little more and use private if the object isn’t that static.
So, it would be like this
private GameObject objectB;
void Start () {
objectB = GameObject.FindGameObjectWithTag("Tag your object with something easy");
}