# Get back True

**URL:** https://discussions.unity.com/t/get-back-true/496633
**Category:** Scripting
**Tags:** Scripting
**Created:** [February 3, 2013, 8:52pm UTC](https://discussions.unity.com/t/get-back-true/496633 "2013-02-03T20:52:56Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![The3DKnight](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/the3dknight/32/194288_2.png) [@The3DKnight](https://discussions.unity.com/u/The3DKnight)
#### Post date: [February 3, 2013, 8:52pm UTC](https://discussions.unity.com/t/get-back-true/496633/1 "2013-02-03T20:52:56Z")

</div>

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:

```auto
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

---

<div class="post-metadata">

### Author: ![Ruthra](https://avatars.discourse-cdn.com/v4/letter/r/ba9def/32.png) [@Ruthra](https://discussions.unity.com/u/Ruthra)
#### Post date: [February 3, 2013, 9:28pm UTC](https://discussions.unity.com/t/get-back-true/496633/2 "2013-02-03T21:28:56Z")

</div>

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

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

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

```

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

---

<div class="post-metadata">

### Author: ![The3DKnight](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/the3dknight/32/194288_2.png) [@The3DKnight](https://discussions.unity.com/u/The3DKnight)
#### Post date: [February 4, 2013, 2:36pm UTC](https://discussions.unity.com/t/get-back-true/496633/3 "2013-02-04T14:36:52Z")

</div>

Yes this is exactly what i needed. Thanx
