I’m trying to set up a charge shot for a weapon in my game, the player holds down the fire button and releases once the charge has built. However once the charge has built and the shot fired the float I have set up to count to 100 wont reset back to 0. This is my script:
void Update ()
{
if (Input.GetButtonDown("Fire5"))
{
charging++;
}
if (Input.GetButtonUp("Fire5"))
{
if ((Time.time > nextFire) && charging >= 100)
{
nextFire = Time.time + fireRate;
Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
audio.PlayOneShot(impact, Volume);
charging = 0;
}
else
{
charging = 0;
return;
}
}
}
I thought putting ‘charging = 0’ would reset the counter but it doesn’t. The counter resets as long as the button is released before it reaches 100.