GameObjectc0=GameObject.Find("A/B/C");GameObjectc1=GameObject.Find("B/C");GameObjectc2=GameObject.Find("C"); 只要name所描述的层级确实存在即可。 最后就是name中用于对层级进行描述的特殊符号’/’,在GameObject的name中其实也可以有这个符号,那查找带有这个符号的name时,由于Find的行为只会把’/’符号解...
hand = GameObject.Find("Monster/Arm/Hand"); } } 2.Transform.Find() 官方解释是通过名字获取到一个子物体(Finds a child by name and returns it),该方法可以获取到隐藏(inactive)的GameObject, 可以通过先获得父对象(active必须为true),再通过寻找孩子Transform.Find() GameObject rootObj = GameObject.Find...
1GameObject root = GameObject.Find("GameObject");23GameObject xxxx = root.transform.Find("xxxx").gameObject;45xxxx.SetActive(true); 注解: 还记得上面我说过用GameObject无法获取天生acive = false的游戏对象,如果你用Transform.Find()的话就可以很好的获取,另外Unity还提供了一个Transform.FindChind()的方法,...
a).Find(string name)通过物体的名字查找 b).FindWithTag(string tag);通过标签获取添加该标签的一个物体 c).FindObjectOfType();依据组件类型 d).FindGameObjectsWithTag(string tag)通过标签获取所有添加该标签的物体数组 返回一个组合 ②Transform: a).获取到物体的Transform组件。然后Transform.gameObject; ③...
name); forreturn = t; return t; } } 递归 代码语言:javascript 复制 static Transform SearchNodeByRecursion(Transform tree, string valueToFind) { if (tree.name == valueToFind) { return tree; } else { if (tree.childCount > 0) { for (int i = 0; i < tree.childCount; i++) { ...
因为这个函数已经取消了FindChild,改成了Find示例如下:假设场景中有一物体:player/body(名为plyer,有一子物体body)原FindChild函数:transform.FindChild("body");Find函数:transform.Find("player/body");区别就是Find函数需要将物体层级标示清楚,而FindChild则是直接使用子物体名作参数 ...
[MenuItem("SaveTransInfo/GetUIChildPath #`")] static void GetUIChildPath() { GameObject obj = Selection.activeGameObject; Transform trans = obj.transform; listParName.Clear(); FindParName(trans); string parPath = ""; for (int i = listParName.Count - 1; i >= 0; i--) { parPath ...
You can also locate a specific child object by name using theTransform.Findmethod:transform.Find("Frying Pan"); This can be useful when a GameObject has a child GameObject that can be added and removed during gameplay. A tool or utensil that can be picked up and put down during gameplay ...
transform The Transform attached to this GameObject. hideFlags Should the object be hidden, saved with the Scene or modifiable by the user? name The name of the object. childCount The number of children the parent Transform has. eulerAngles The rotation as Euler angles in degrees. forward Return...
Debug.LogError("找不到对象:MyGameObject"); } } “` 3、使用Find系列函数的注意事项: 尽量避免在Update或频繁调用的方法中使用Find系列函数,因为它们可能会产生性能开销。 如果需要查找子对象,请确保提供正确的路径。GameObject.Find("Parent/Child")。