//Assuming parent is the parent game object
for (int i = 0; i < parent.transform.childCount; i++)
{
var child = parent.transform.GetChild(i).gameObject;
if (child != null)
child.SetActive(false);
}
How to deactivate all children in Unity?
-
11-06-2023 - |
Domanda
How do I only deactivate all children in unity and leaving the parent active?
Soluzione 2
Altri suggerimenti
foreach (Transform child in transform)
child.gameObject.SetActive(false);
Give this a try:
public void DisableChildren()
{
foreach (Transform child in transform)
{
child.gameObject.SetActiveRecursively(false);
}
}
JS version (if needed):
function DisableChildren()
{
for (var child : Transform in transform)
{
child.gameObject.SetActiveRecursively(false);
}
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow