wep spawn to hand parent when key pressed?

so i have a bone on my player as r_hand_bone and is the location where i want my weapon to be placed when i press 1 2 or 3

so i can see what i have you know, detroy the current wep and replace it with another
aka swaping weapons

this is my code so far but without the wepon spawn, thanks in advance :slight_smile:

var blockPrefabs1 : GameObject;
var blockPrefabs2 : GameObject;
var blockPrefab2 : GameObject;
var blockPrefab3 : GameObject;
var hit : RaycastHit;
var range : float = 4;
var blockLayer : LayerMask = 1;
var chosenblock = 1;
var crosshair : GameObject;
var bullet : GameObject;
var pnt : Transform;
 
function Update () {
    if (Input.GetMouseButtonDown(0))
        PlaceBlock();
    if (Input.GetMouseButtonDown(1))
        DestroyBlock();
    if (Input.GetKey("2"))
    chosenblock = 1;
    if (Input.GetKey("3"))
    chosenblock = 2;
    if (Input.GetKey("1"))
    chosenblock = 0;
        if (Input.GetKey("4"))
    chosenblock = 3;
    if(Input.GetButtonDown("Fire1") && chosenblock == 3){
var ray = Camera.main.ScreenPointToRay (Vector3(Screen.width/2,Screen.height/2,0));
var hit : RaycastHit;
if (Physics.Raycast (ray, hit, 10000)) {
    Debug.DrawLine (ray.origin, hit.point);
    crosshair.transform.position = hit.point;
    pnt.transform.LookAt(hit.point);
   x = Instantiate(bullet,pnt.transform.position,pnt.transform.rotation);
 x.rigidbody.AddForce(pnt.transform.forward * 20000);
}}
}
 
function PlaceBlock() {
    if (HitBlock1()) {
    if (chosenblock == 1)
        var cube = Instantiate(blockPrefabs1 ,hit.transform.position + hit.normal, Quaternion.identity); 
    else if (chosenblock == 2)
    cube = Instantiate(blockPrefabs2 ,hit.transform.position + hit.normal, Quaternion.identity);
    }
}
 
function DestroyBlock(){
    if(HitBlock()){
    for (var child : Transform in hit.transform) {
    if (child.tag == "dirt"){var cube = Instantiate(blockPrefab3 ,hit.transform.position, Quaternion.identity);
    Destroy(hit.transform.gameObject);
    }
    else if (child.tag == "stone") cube = Instantiate(blockPrefab2 ,hit.transform.position, Quaternion.identity);
        Destroy(hit.transform.gameObject);
    }}
}
 
function HitBlock() : boolean{
    if(Physics.Raycast(transform.position, transform.forward, hit, range, blockLayer))
    {
        if (hit.collider.gameObject.tag == "Blocker")
            return true;
    }
 
    return false;
}
function HitBlock1() : boolean{
    if(Physics.Raycast(transform.position, transform.forward, hit, range, blockLayer))
    {
        if (hit.collider.gameObject.tag == "nobuild")
            return false;
            else return true;
    }
}

So you change chosenblock variable based on number pressed and want to instantiate a new weapon…
Recommendation is this, Instantiate 3 gameObjects of weapons and disable renderers of all of them. Then make that bone transform parent of all of them and set their positions to what it should be and then when changing this number also enable renderer of the one which should be shown and disable all others.
You can define an id for each weapon on an script and sendMessage to it something like
function EnableWeapon(id:int)
{
renderer = (id = myId);
}
//And send this message to all of them
//SendMessage(“EnableWeapon”,chosenblock);

Also some advice unrelated to this
Make different components for different purposes. Don’t post unrelated code for shooting and … in answers sites like this, the update method was enough. and it’s a good idea to write variable names as chosenBlock instead of chosenblock