如何停用Unity中的所有孩子?

时间:2014-03-09 05:32:05

标签: c# unity3d

我如何仅统一停用所有儿童并让父母保持活动状态?

3 个答案:

答案 0 :(得分:5)

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

答案 1 :(得分:3)

foreach (Transform child in transform)
    child.gameObject.SetActive(false);

答案 2 :(得分:0)

尝试一下:

public void DisableChildren()  
{    
    foreach (Transform child in transform)     
    {  
        child.gameObject.SetActiveRecursively(false);   
    }   
}

JS版本(如果需要):

function DisableChildren()   
{   
    for (var child : Transform in transform)    
    {   
        child.gameObject.SetActiveRecursively(false);  
    }  
}
相关问题