Attaching an object to a bone?

Hi. I am entirely new to Unity and last night I mucked around following a tutorial to set up a simple 3rd person shooter (I mean REALLY SIMPLE), no animations or textures. Just a cube that shoots balls and moves around.

I can see a lot of potential for Unity so I just wanted to check if it can do something and how easy it is... I know how to import a 3d model from Blender so thats all ok.

Question: I just wanted to know what sort of code would be used to attach an object to the bone of another object. Thanks :)

On Unity bones are just GameObjects with Transform components on, just like any other GameObject. So you attach one GameObject to a bone by making the bone Transform the parent of the GameObject you want attached.

myGameObject.transform.parent = myBone.transform;

To control the relative alignment of the attached GameObject relative to the bone, you can set the localPosition and localRotation of the Transform of the attached GameObject.

I'm trying this too

function Update () {

Sword_500Knight.transform.parent = Hand_R.transform;
}

but I get: unknown identifier for both Hand_R (the bone of player model which script is on) and Sword_500Knight (the prefab sword)

Hi,

I tried this and it works fine, all i did is make 2 vars, 2 Game-Objects,and you can assign the hand and the sword in inspector.
But the problem is the sword needs to have the same position or transform as hand, and than i found this :slight_smile: