Parenting & Re-Parenting

From ETC Public Wiki
Revision as of 19:28, 14 April 2011 by Ewkang (talk) (Created page with 'To parent (or re-parent) a [ GameObject] to another GameObject, simply assign the […')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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: