Description
The Parent
property of a GameObject
represents the parent GameObject
in the scene hierarchy. This property allows you to access or modify the parent of the current GameObject
, enabling you to change its position in the hierarchy or retrieve its parent for further operations.
Usage
To access the parent of a GameObject
, simply use the Parent
property. You can also set this property to change the parent of the GameObject
.
Note that changing the parent of a GameObject
will affect its transform, as its position, rotation, and scale are relative to its parent.
Example
// Accessing the parent of a GameObject
GameObject myObject = new GameObject();
GameObject parentObject = myObject.Parent;
// Setting a new parent for a GameObject
GameObject newParent = new GameObject();
myObject.Parent = newParent;