Equipping weapons with inventory system?

Hello, i am developing a fps game yet i am having difficulty figuring out how to make a proper system for the different guns. I have a free asset inventory system already set up and working (the inventory system is the one made by Brackeys to be exact) and melee weapons work just fine, but the guns are not functioning as i would like them to. So far with my gun script, the script was not made to function with an inventory system, so when ever i click the button that will make the gun fire a bullet, it fires a bullet and makes the ammo go down even if i do not have the gun equipped.

I would like to understand how to make the gun fire a bullet and make the ammo go down only when i have it equipped.

Here is the current shooting script if that would help

static var ammo = 30;
static var maxAmmo = 30;
var key : String = "mouse 0";
var bullet : Rigidbody;
var speed : float = 150;

function Update () 
{
	if(Input.GetKeyDown(key))
	{
		if(ammo > 1)
		{
			shoot();
			{
				audio.Play();

			}
		}
	}
}
function shoot()
{
	var bullet1 : Rigidbody = Instantiate(bullet, transform.position, transform.rotation);
	bullet1.AddForce(transform.forward * speed);
	ammo --;
}
function OnGUI ()
{
	GUI.Label(Rect(10, 10 ,500, 500), "Ammo:"+ammo);
}

Sorry if this sounds overly complicated
Thanks

Why not just add in a simple variable like “Equipped”?

 static var ammo = 30;
 static var maxAmmo = 30;
 var key : String = "mouse 0";
 var bullet : Rigidbody;
 var speed : float = 150;
static var Equipped = false;
 
 function Update () 
 {
     if(Input.GetKeyDown(key) && Equipped == true)
     {
         if(ammo > 1)
         {
             shoot();
             {
                 audio.Play();
 
             }
         }
     }
 }
 function shoot()
 {
     var bullet1 : Rigidbody = Instantiate(bullet, transform.position, transform.rotation);
     bullet1.AddForce(transform.forward * speed);
     ammo --;
 }
 function OnGUI ()
 {
     GUI.Label(Rect(10, 10 ,500, 500), "Ammo:"+ammo);
 }

Then, in the inventory, just set “Equipped” as true or false, depending on if it is being used.