Fire Rate Issues

This is commonly called a “cooldown timer.” You can google for examples and tutorials, but the simplest way is this:

  1. have a private float gunHeat; variable

  2. In Update(), if that variable is greater than zero, subtract Time.deltaTime from it (this cools down the gunHeat)

if (gunHeat > 0)
{
  gunHeat -= Time.deltaTime;
}
  1. When you go to fire:
    — A. only fire if that gunHeat variable is zero or less.
    — B. set that variable to the time (in seconds) you want to have between shots.
if (UserWantsToFireTheGun)
{
  if (gunHeat <= 0)
  {
    gunHeat = 0.25f;  // this is the interval between firing.
    ActuallyDoTheFiring();
  }
}
4 Likes