So I am making an FPS game where the player has a fully automatic primary weapon, and a semi auto secondary. In order for the player to be able to shoot with the primary gun he needs to be holding the left mouse button and both “isActive” and “canShoot” need to be true. The code looks something like this:
void Update ()
{
if (isActive && canShoot && Input.GetKey("mouse 0")
{
Shoot();
}
}
The issue I am having, is when the player switches back to the primary weapon while holding mouse 0, it near instantly shoots the entire 30 round magazine, completely ignoring the fire rate I have set in Shoot(). isActive and canShoot are both false during this swapping gun period, so why does it still listen to the getkey, and seemingly shoot all the bullets from the time I spent holding mouse 0. I’ve tried writing this in all sorts of ways but haven’t been able to come up with a fix yet.