Get back True

Hi so while i was testing project i noticed that while i hold down my fire button , gun shoots(rifle), but if i change my weapon while i was holding my fire button,and then i change back to that gun again i can’t shoot.I understand why.
Because i order to set my gun shoot automatic i used CanFire = true; so if its false it can’t shoot.That’s ,when i change my weapon it goes false and i can’t shoot. So my question is how can i make CanFire = true every time my gun is selected

Here is part of code:

if (Rifle == false ) 
{

if(Input.GetButton("Fire1"))
	{	
	if (ammo >0)
		{
			 
			Fire();
		}
	}
}


function Fire () 
{



if(CanFire == true)
{

	var bullet = Instantiate(BulletPrefab, GameObject.Find("spawnPoint").transform.position, GameObject.Find("Obj").transform.rotation);
	bullet.rigidbody.AddForce(bullet.transform.forward * force);
//If false stop shooting
	CanFire = false;
		yield WaitForSeconds (FireRate);
	CanFire  = true;
	
	ammo -= 1;
	
	
	
}

}

Any tips or help.How to fix this.

Thanx

-3DK

I don’t know if I understand this right but,

Maybe you could add a setter in your firing script like that in c# :

	public void WeaponSwitched(bool canFire) {
		CanFire = canFire;
	}

Which is accessed by your weapon switching script after a switch, passing true.

Yes this is exactly what i needed. Thanx