Вопрос

How do I only deactivate all children in unity and leaving the parent active?

Это было полезно?

Решение 2

//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);
}

Другие советы

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);  
    }  
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top