Parenting & Re-Parenting

From ETC Public Wiki
Revision as of 19:30, 14 April 2011 by Ewkang (talk)
(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: http://unity3d.com/support/documentation/ScriptReference/Transform-parent.html