简体   繁体   English

如何在统一 c# 中获取 GameObject 的孩子?

[英]How to get children of an GameObject in unity c#?

so I have an GameObject that I want to disactivate the child of the child of the GameObject I want to know how to get the child of child of the GameObject, I know there Are lots of ways to disactivate it, but I want something similar like GetComponentInChildren but as you may know it uses to get component, I did search it in google but it has done with transform which for my case I don't want to use transforms, Thanks..所以我有一个游戏对象,我想停用游戏对象的孩子的孩子我想知道如何获得游戏对象的孩子的孩子,我知道有很多方法可以停用它,但我想要类似的东西GetComponentInChildren 但您可能知道它用于获取组件,我确实在谷歌中搜索过它,但它已经完成了转换,对于我的情况我不想使用转换,谢谢..

For anyone looking for that question I just found the answer by myself you can simply go like:对于任何寻找该问题的人,我只是自己找到了答案,您可以简单地 go 喜欢:

public GameObject child;
void Start()
{
    child = GameObject.Find("PlayerController").GetComponentInChildren<FixedTouchField>().gameObject;
}
void Update()
{

}
void DisactivateGameObject()
{
child.SetActive(false);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM