set gameobject parent in unity scripting code example
Example 1: setparent unity
using UnityEngine;public class ExampleClass : MonoBehaviour
{
public GameObject child; public Transform parent;
public void Example(Transform newParent)
{
child.transform.SetParent(newParent);
child.transform.SetParent(newParent, false);
child.transform.SetParent(null);
}
}
Example 2: unity change parent in script
player.transform.parent = newParent.transform;
Example 3: set parent of gameobject unity
child.transform.SetParent(newParent);