1 private void Start()
2 {
3 parentObject = GameObject.Find("Parent");// The name of the parent object
4 childObject = parentObject.transform.GetChild(0).gameObject; // the parent index (starting from 0)
5 }
1 // spawns object
2 objToSpawn = new GameObject("Start");
3
4 // add Components
5 objToSpawn.AddComponent<Rigidbody>();
6 objToSpawn.AddComponent<MeshFilter>();
7 objToSpawn.AddComponent<BoxCollider>();
8 objToSpawn.AddComponent<MeshRenderer>();
9
10 // sets the obj's parent to the obj that the script is applied to
11 objToSpawn.transform.SetParent(this.transform);
1Transform[] transforms = this.GetComponentsInChildren<Transform>();
2
3 foreach(Transform t in transforms)
4 {
5 if (t.gameObject.name == "Child")
6 {
7 Debug.Log ("Found " + t);
8 }
9 }