I am working in a C# script that will reduce 1 to my weapon’s ammo everytime the player press the left mouse button. I got no errors, so i think everything is fine, but when i test the game it only reduces one time, not everytime. So if i say that my ammo is 5, when i shoot it reduces to 4 and then it doesn’t reduce the ammo anymore.
That’s the script i am using
public GameObject txt;
private int ammo;
public int bullets;
void Start()
{
ammo = bullets;
UpdateAmmo();
}
void Update()
{
if (Input.GetButtonDown("Fire1"))
{
ammo = bullets - 1;
UpdateAmmo();
}
}
void UpdateAmmo()
{
txt.GetComponent<UnityEngine.UI.Text>().text = ammo.ToString();
}
}