Muzzle flash stop when reloading?

Hi all, I have wrote this script that spawns a simple particle effect of a muzzle flash at the end of my gun when the LMB is clicked, I have other scripts on my gun that control shooting raycasts and reloading ect, but I’m having a problem with how I would stop the muzzle flash for being able to be spawned when the gun is reloading, I have done so with my raycasts and animations but I don’t know how I would do it for this, can anyone help me out please?

var muzzleFlash : GameObject;

var spawnPoint : Transform;

function Update () {

if(Input.GetButtonDown(“Fire1”)){
Instantiate(muzzleFlash, spawnPoint.position, spawnPoint.rotation);
}
}

var muzzleFlash : GameObject;
var spawnPoint : Transform;

function Update () {

if(Input.GetButtonDown("Fire1")){
Instantiate(muzzleFlash, spawnPoint.position, spawnPoint.rotation);
 } 
if(Input.GetButtonUp("Fire1")){
Destroy(muzzleFlash);
 }
}

this is so when the key comes up, the gameobject will destroy

As I said. You should add a reload variable to keep track of if you are reloading or not. Here is something to help you along the way:

var muzzleFlash : GameObject; 
        var spawnPoint : Transform; 
        var amountOfShots = 8; 
        var reloadTime = 1.5;
    
        private var reloading = false;
        
    function Update (){
        if(Input.GetButtonDown("Fire1") && !reloading){ //Check for input and that we aren't reloading
    
        //Exclamation mark pretty much means "is false"
             Shoot(); 
            }
        }
        
        if(Input.GetKeyDown("r")){ 
            Reload(); 
    }
        
    function Reload (){
        reloading = true; //Set reloading to true because... We are reloading
        
        yield WaitForSeconds(reloadTime); 
    
        amountOfShots = 8; 
        reloading = false; //Set reloading to false because we are done reloading
    }
        
     function Shoot (){
            //All of this below will now only execute when we are not reloading
        if(amountOfShots > 0){ //If we have ammunition left
            amountOfShots--;
        
            Instantiate(muzzleFlash, spawnPoint.position, spawnPoint.rotation);
        }
    }

Not tested, but might work and you should be able to get an idea of what to do.

I’ve figured it out now, I have posted the script below thanks for the help and directions!!

var muzzleFlash : GameObject;

var spawnPoint : Transform;

var fullClip : int = 8;

var bulletsLeft : int = 8;

function Update () {

if(Input.GetButtonDown(“Fire1”)){

if(bulletsLeft > 0 ){

bulletsLeft – ;

Instantiate(muzzleFlash, spawnPoint.position, spawnPoint.rotation);

}

}

if(Input.GetButtonDown(“r”)){

bulletsLeft = fullClip ;

}

}