Weapon Parenting...v.2.0

I’ll make this fairly simple. In code form, how would I go about creating an origin point for which an object would be parented.(I know about drag and drop, but i have multiple weapons.)

For instance if the right hand bone is the origin point, how would I go about placing a sword there. The code I have thus far parents the object, but it always appears at a strange angle because I added a child to the right hand and parented the weapon to the child. I’d like to do away with this and parent directly to the hand bone.

I’ve attached a picture here of what happens when I call this code.


function EqpWpn() {//set check so that more than one barrier can't be cast. var newEq=GameObject.Find("WeaponOrigin"); animation.CrossFadeQueued("Using Magic"); var clone; clone=Instantiate (weapon1,newEq.transform.position,Quaternion.identity); //send message, or add this to player obj code to update barrier hp. clone.transform.parent=newEq.transform;//make it parent. }

After you parent the item, make sure to recenter it based on the parent.

clone.transform.localPosition = new Vector(0,0,0);
clone.transform.localRotation = Quaternion.identity // or whatever rotation you want it to be relative to newEq;