1.GetComponentsInChildren()
查找单个子物体
GameObject childObject=GetComponentInChildren<Transform>();
查找多个子物体
Transform[] myTransforms = GetComponentsInChildren<Transform>();
foreach (var child in myTransforms){
Debug.Log(child.name);
}
2.transform.Find()
此方法通过名字寻找特定子物体,只能寻找一级子物体,不能寻找二级子物体
路径查找
查找二级子物体
transform.Find("Canvas/Image").GetComponent<Image>();
3.可以通过tag找物体的,不过是针对所有物体进行搜索
GameObject.FindGameObjectWithTag()