如果想獲取一級子節點

1 foreach (Transform child in this.transform) 2 { 3 Debug.Log(child.name); 4 }
如果想獲取所有子節點

1 foreach (Transform child in gameObject.GetComponentsInChildren<Transform>()) 2 { 3 Debug.Log(child.name); 4 }
這樣會包括所有帶有transform屬性的子節點。
在unityAPI中也有介紹

1 public class ExampleClass : MonoBehaviour { 2 void Example() { 3 foreach (Transform child in transform) { 4 child.position += Vector3.up * 10.0F; 5 } 6 } 7 }
歡迎廣大unity興趣愛好者加群學習165628892 (進群備注:博客) 隨時提出問題解決問題!
樹欲靜而風不止,子欲養而親不待。
2016年12月8日15:12:38