Player weapon swap

I am working on a player weapon switch script for my game and I am not sure what I am doing incorrectly. I can get the weapons to switch but only once and they do not switch back. Here is the code that I am working with.

var selectedWeapon : float = 0;
var  projecile 				   : Rigidbody;
static var  projMuzzleVelocity : float = 60.0; // in metres per second
static var  RateOfFire     	   : float = 0.5;
static var  Inaccuracy         : float = 0.5;
static var  fireTimer          : float = 0.5;
static var hasShotGun 	   	   : boolean = false; 
static var hasHandGun      	   : boolean = false; 
print("Has HandGun:" + hasHandGun);
print("Has ShotGun:" + hasShotGun);

function Start()
{
    fireTimer = Time.time + RateOfFire; 
    selectedWeapon = 0;
    print("Selected Weapon"+selectedWeapon);
    
}
 
function Update () 
{
	if(Input.GetKeyDown("1") )
	{
		 selectedWeapon = 1;
		 print("Selected Weapon"+selectedWeapon);
	}
	
	else if(Input.GetKeyDown("2"))
	{
		selectedWeapon = 2;
		 print("Selected Weapon"+selectedWeapon);
	}
	
     if(Input.GetButtonUp("Fire1")&& hasHandGun == true && HealthController.AMMO != 0 && selectedWeapon == 1)
    {
	        
	       if (Time.time> fireTimer)
	       {
	         //GameObject.projectile;
	         var muzzleVelocityHG : Vector3 = transform.forward;
	 
	         if (Inaccuracy != 0)
	         {
	          var rand1 : Vector2 = Random.insideUnitCircle;
	          muzzleVelocityHG += new Vector3(rand1.x, rand1.y, 0) * Inaccuracy;
	         }
	         muzzleVelocityHG = muzzleVelocityHG.normalized * projMuzzleVelocity;
	         //Debug.Log("Fire1");
	         clone = Instantiate(projecile, transform.position, transform.rotation);
	         clone.velocity = muzzleVelocityHG;
	        
	         fireTimer = Time.time + RateOfFire;
	         HealthController.AMMO -= 1.0;
	         Destroy(clone.gameObject,1.5);
	       }
	     }
	      
	    if( Input.GetButtonUp("Fire1")&& hasShotGun == true && HealthController.AMMO != 0 && selectedWeapon == 2)
	    {
	       if (Time.time> fireTimer)
	       {
	         //GameObject.projectile;
	         var muzzleVelocity : Vector3 = transform.forward;
	 
	         if (Inaccuracy != 0)
	         {
	          var rand2 : Vector2 = Random.insideUnitCircle;
	          muzzleVelocity += new Vector3(rand2.x, rand2.y, 0) * Inaccuracy;
	         }
	         muzzleVelocity = muzzleVelocity.normalized * projMuzzleVelocity;
	         //Debug.Log("Fire1");
	         clone = Instantiate(projecile, transform.position, transform.rotation);
	         clone.velocity = muzzleVelocity;

	         fireTimer = Time.time + RateOfFire;
	         HealthController.AMMO -= 1.0;
	         Destroy(clone.gameObject,1.5);
	       }
	     }
}

I think it has something to do with me not storing my previous weapon but that is just my best guess. Any ideas on what I am doing wrong or what I could be doing better would be great.

Thanks for the help.

Just to clarify, a few thing.

you start with weapon No. 0, and hit 1 to use weapon No.1, hit 2 to use weapon No.2 right?
Are you asking us why it wont go back to weapon No.0?

If so, you need to edit the values of selectedWeapon when you hit the numeric keys 1&2.

also can you post your debug messages when you…

  1. have weapon 1 selected and switch to weapon 2
  2. switch back to weapon 1

So all of the debug comments are working AFAIK. The weird thing is that if you pick up the shotgun, slot 2, and select slot 1, the handgun, and you do not have the handgun, you will not fire and then be able to switch back over to slot 2, the shotgun, and fire.

The problem of not being able to switch only comes after you fill up both slots with weapons.