Parenting & Re-Parenting

From ETC Public Wiki
Jump to: navigation, search

To parent (or re-parent) a GameObject to another GameObject, simply assign the parent field of the child GameObject's Transform to the Transform of the new parent GameObject. Example:

aGameObject.transform.parent = anotherGameObject.transform;

Note that in doing this, the local position, scale and rotation of the child will be modified to make it relative to its new parent, but the child's world-relative position, scale, and rotation will remain the same.

For more information, see the Transform.parent script reference: