Gun Changing Problem

Guys,Please help me if you can
here the problem
I can’t change guns while pressing 1 or 2, I can only do that if I press both the gun changing keys as well as the Firing Key
here’s my script

#pragma strict
var PrimaryWeapon : Transform;
var firesound : AudioClip;
var shootForce : float = 1000;
var SecondryWeapon : Transform;
var Force2 : float = 1000;
var SecondrySound : AudioClip;
var weaponnumber = 1;

function Start () {

}

function Update ()
{
if (Input.GetButtonUp(“Fire1”))
{
if (weaponnumber == 1)
{
var bulletfire = Instantiate (PrimaryWeapon,GameObject.Find(“bullet_SpawnPoint”).transform.position,Quaternion.identity);
bulletfire.GetComponent.().AddForce(transform.forward *shootForce);
GetComponent.().Stop();
GetComponent.().PlayOneShot(firesound);
}
if (weaponnumber == 2)
{
var SecondryWeapon = Instantiate (SecondryWeapon,GameObject.Find(“bullet_SpawnPoint”).transform.position,Quaternion.identity);
SecondryWeapon.GetComponent.().AddForce(transform.forward *Force2);
GetComponent.().Stop();
GetComponent.().PlayOneShot(SecondrySound);
}

//weapon change code
if (Input.GetKeyUp(“1”))
{
weaponnumber = 1;
}
if (Input.GetKeyUp(“2”))
{
weaponnumber = 2;
}
}
}

help would be appreciated

your weapon change if statements are within the scope of the fire if statement…

please use [code ][/code ] tags when pasting code into the forums

no,i can just press 2 when ever i want to change.That how it should work but it doesn’t
For example just like GTA SAN ANDREAS when you press q or e to cahnge weapon

yes…

function Update () 
{
    if (Input.GetButtonUp("Fire1"))
    {
        if (weaponnumber == 1)
        {
            ...
        }
        if (weaponnumber == 2)
        { 
            ...
        }

        //weapon change code
        if (Input.GetKeyUp("1"))
        {
            ...
        }
        if (Input.GetKeyUp("2"))
        {
            ...
        }
    }
}

the if statements which handle the input to change the weapons are within the scope of the if statement controlling the fire, therefore you must be pressing fire and the change key at the same time in the same frame for them to work. This is where your issue lies, you are going to need to change you code to allow the logic you want.

i still cant understand what you want to say
can you just test it and fix it and post it
please

hey

thanks to you,i fixed it
man you are like a god to me
many thanks
appreciated that