Instantiate on bone transform

Hey All,

I am trying to instantiate a game object (weapon) on a bone that I have in my armature which is specifically there for this purpose. I am having issues with getting this to work correctly, I’m assuming there is a problem with my syntax or my lack of knowledge with unityscript. Anyhow I have been searching and trying to figure this out, but have not been able to and would like some help now.

I dragged the bone that I wanted to be the parent from the hierarchy to the inspector assuming this would be the vector3 that I needed. However I keep getting this error.

Assets/Scripts/Script_InstantianteAndParent.js(17,36): BCE0023: No appropriate version of ‘UnityEngine.Object.Instantiate’ for the argument list ‘(UnityEngine.GameObject, UnityEngine.Transform, UnityEngine.Quaternion)’ was found.

Here is my code:

var weaponPrefab : GameObject;
var gunBoneRight : Transform;

function Update () {

    if (Input.GetButtonDown ("Fire1")){
	gunBoneRight = Instantiate (weaponPrefab,gunBoneRight,transform.rotation);
    }
}

If I replace “gunBoneRight” with transform.position it works just not in the correct location.

Any advice would be much appreciated!

You should use gunBoneRight.position to define the gun position, and possibly gunBoneRight.rotation to define its orientation. The instantiated weapon should not be assigned to gunBoneRight, since this variable is the bone reference:

var weaponPrefab : GameObject;
var gunBoneRight : Transform; // drag the gun bone here
var weapon : Transform; // this will be the weapon

function Update () {
  if (Input.GetButtonDown ("Fire1")){
    weapon = Instantiate (weaponPrefab, gunBoneRight.position, gunBoneRight.rotation);
  }
}