set parent of gameobject unity code example
Example 1: unity reference parent gameobject
transform.parent.gameObject
Example 2: 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 3: set parent of gameobject unity
child.transform.SetParent(newParent);
Example 4: how to get parent gameobject in unity
childObject.transform.parent.gameObject