unity reference child object code example

Example 1: unity reference parent gameobject

transform.parent.gameObject //Use this to reference the parent of the gameobject

Example 2: how to reference a child object unity

private void Start()
    {
        parentObject = GameObject.Find("Parent");// The name of the parent object
        childObject = parentObject.transform.GetChild(0).gameObject; // the parent index (starting from 0)
    }

Example 3: unity instantiate prefab as child

//Instantiate Object
     GameObject go = Instantiate(A, new Vector3 (0,0,0), Quaternion.identity) as GameObject;
     // Tranform as child
     go.transform.parent = GameObject.Find("Stage Scroll").transform;