GameObject parentHide = GameObject.Find("GameObjectHide"); Debug.Log("找父级隐藏物体,是否找到:" + (parentHide != null)); // 找子级隐藏物体 GameObject childHide = GameObject.Find("ChildHide"); Debug.Log("找子级隐藏物体,是否找到:" + (childHide != null)); } 1. 2. 3. 4. 5. 6....
1,Find(名字/路径) a, 遍历孩子(不包括子孩子。。。) foreach( Transform child in this.transform) { Debug.Log(child.name); } 1. 2. 3. 4. 结果如下: b, 使用Find查找孩子 a1,如查找Cylinder(孩子) this.transform.Find("Cylinder"); a2,查找孩子Cylinder的孩子Cube,也就是查找孙子 this.transform...
所以,通过Transform可以间接获取到子对象。GetChild()GetChildCount。 1 2 3 4 5 var transform = GetComponent<Transform>(); for (int i = 0; 0 < renderers.Length; i++) { transform.GetChild(i).gameObject.SetActive(true); } 本文会经常更新,请阅读原文:https://blog.walterlv.com/post/unity-st...
voidObjectFind(){// 找父级GameObject parent = GameObject.Find("GameObject"); Debug.Log("找父级物体,是否找到:"+ (parent !=null));// 找子级GameObject child = GameObject.Find("Child"); Debug.Log("找子级物体,是否找到:"+ (child !=null));// 找父级隐藏物体GameObject parentHide = GameObj...
1. GameObject.Find 通过名字或路径查找游戏对象。 GameObject.Find("GameObject"); GameObject.Find("GameObject/ChildGameObject); 该方法只会返回一个active的,即未隐藏对象。 如果参数包含 '/' 字符,它会像路径名一样遍历层次结构,所以效率低。故建议在Start()或Awake()中查找对象并保存引用,切忌在Update()中动...
Note:If you wish to find a child GameObject, it is often easier to useTransform.Find. Note:If the game is running with multiple scenes thenFindwill search in all of them. 正如文档上所说,是通过name这个参数,GameObject.Find会在所有运行着的场景中寻找处于Active状态的游戏对象。可以传入字符串作为...
1 GameObject.Find("GameObject"); 2 GameObject.Find("GameObject/ChildGameObject); --- 总:使用目录结构进行查找较通过名字查询缩短了查询时间和范围,也更能确定对象,缺点是一旦路径或结构调整后,容易影响到程序。方便使用,但效率低下。 --- FindWithTag方法: static...
Transform Find(String name) Transform FindChild(String name)1.查找名为name的(transform.gameObject)...
GameObject childHide = GameObject.Find("ChildHide");Debug.Log("找⼦级隐藏物体,是否找到:" + (childHide != null));} 测试结果如下图:当有使⽤GameObject.Find("GameObject"), 场景中有多个名为“GameObject”的物体存在时,将每个“GameObject”设置为不同的标签,多运⾏⼏次查看结果。测试场景...
Instantiate(go) as GameObject; List<Transform> findTest = new List<Transform>(); string[] findNames = new string[] { "Directional light","GameObject (3)","GameObject (4)"}; FindChild(target.transform, new List<string>(findNames), ref findTest); for (int i = 0; i < findTest....