我如何仅统一停用所有儿童并让父母保持活动状态?
答案 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);
}
}