https://answers.unity.com/questions/52560/gameobjectfind-work-on-inactive-objects.html
GameObject.Find()只能找到active的物体
Transform.Find()和Transform.FindChild()能找到active为false的物体,其中FindChild()方法已过时,不推荐使用。

GameObject test1 = GameObject.Find("Cube/Cube1");
GameObject test2 = transform.Find("Cube1").gameObject;
if (test1 == null)
{
Debug.LogError("test1 is null");
}
if (test2 == null)
{
Debug.LogError("test2 is null");
}

本文探讨了在Unity中如何使用GameObject.Find(), Transform.Find()和Transform.FindChild()方法来查找场景中的物体。GameObject.Find()仅能查找处于激活状态的物体,而Transform.Find()和Transform.FindChild()则可以定位到非激活状态的物体,但后者已过时。

3万+

被折叠的 条评论
为什么被折叠?



