Note: If you wish to find a child GameObject, it is often easier to use Transform.Find. Note: If the game is running with multiple scenes then Find will search in all of them. 正如文档上所说,是通过name这个参数,GameObject.Find会在所有运行着的场景中寻找处于Active状态的游戏对象。可以传入...
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...
hand = GameObject.Find(“Hand”); hand = GameObject.Find(“/Hand”); hand = GameObject.Find(“/Monster/Arm/Hand”); hand = GameObject.Find(“Monster/Arm/Hand”); } } 注解: GameObject.Find()使用起来很方便,就是如果你的这个GameObject天生acive = false的话。那么你用GameObject.Find()是永远...
GameObject root = GameObject.Find("root"); root.SetActive(false);//根节点为空//总是查找失败root.transform.Find("root/AnyChildObjectName"); 实际开发: 实际开发中会将功能预制体放到一个可见的GameObject目录下,将这个GameObject目录作为查找根节点,下面的所有对象(隐藏、非隐藏)都可以查找到。 你可以把”m...
……我是不采用GameObject.Find的方法的……我自己写了个对某个物体的子物体下的DFS、BFS查找。用法跟...
[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 the Transform.Find method: 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 ...
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++) { ...
transformThe Transform attached to this GameObject. hideFlagsShould the object be hidden, saved with the Scene or modifiable by the user? nameThe name of the object. childCountThe number of children the parent Transform has. eulerAnglesThe rotation as Euler angles in degrees. ...
public static GameObject Find (string path); 该函数按 name 查找 GameObject,如果找到了就返还该物体,否则返还 null。并且此函数仅返回活动 GameObject。如果 name 包含“/”字符,则会向路径名称那样遍历此层级视图。 样例: void Start() { var go = GameObject.Find("物体1/物体2"); if (!go) print("...