how to parent objects in script unity code example
Example 1: unity reference parent gameobject
transform.parent.gameObject //Use this to reference the parent of the gameobject
Example 2: unity change parent in script
player.transform.parent = newParent.transform;
Example 3: set parent of gameobject unity
child.transform.SetParent(newParent);