- Home /
how to make a game object a child of antohter while game is playing
i am making a ninja game and when you aproach the sword a GUI will pop up saying press this button to eguip, and my problem is i don't no how to script it so when you pick it up it becomes a child of the character. If you could show me how to script that (preferably in javascript) that would be great!
Answer by _Petroz · Jan 15, 2011 at 09:04 AM
You can parent GameObjects using their transform:
transform.parent = otherGameObject.transform
http://unity3d.com/support/documentation/ScriptReference/Transform-parent.html
What if your object is a prefab? "Setting the parent of a transform which resides in a prefab is disabled to prevent data corruption."
Answer by efge · Jan 15, 2011 at 08:14 AM
You could use a FixedJoint or search unityAnswers for "parenting".
This is a little bit to much work if it is possible with a very simple line of code! Have a look @_Petroz answer!