查找游戏对象的孩子的孩子 [英] Find children of children of a gameObject
本文介绍了查找游戏对象的孩子的孩子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在场景中有一个预制件,我想访问该预制件的子代,该预制件的结构如下:
I have a prefab in scene and I want to access a child of that prefab, Structure of that prefab is like this:
PauseMenu
UI_Resume
TextField
TextField2
UI_Side_Back <---- (I need this child)
UI_Home
transform.FindChild
只返回一级子级,loop
在该变换中也是一级子级中的循环:
transform.FindChild
return just first level child and loop
in that transform is loop in first level child too:
foreach (Transform item in PooledPause.transform) {
Debug.Log(item.name);
}
我认为它需要是一种递归方法或其他东西.我怎样才能找到那个孩子?
I think it's need to be a recursive method or something. How can I find that child?
推荐答案
您可以使用路径查找转换:
You can use a path to find a transform:
var target = transform.Find("UI_Resume/TextField2/UI_Side_Back");
来自 文档Transform.Find
:
如果名称包含/"字符,它将像路径名称一样遍历层次结构.
If name contains a '/' character it will traverse the hierarchy like a path name.
这篇关于查找游戏对象的孩子的孩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文