how to set parant of game object from code unity code example
Example 1: set parent of gameobject unity
child.transform.SetParent(newParent);
Example 2: how to parent something unity
public GameObject GameObjectYouWantToParent;
public GameObject TheNewParent;
Transform GameObjectsTransform = GameObjectYouWantToParent.transform;
GameObjectsTransform.parent = TheNewParent;