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();
  }
}
5 Likes
Using coroutine to "control" while loop not working
How to implement time delay in damage (Invincibility Frames)
trying to make a cooldown system, but it does not work (it appears error CS1002 and error CS1513)
How to Start a Coroutine once when a bool is true
How to add shoot cooldown?
AddForce works from one side but not the other
Trouble with variables
Need help with my movement script
How to I make part of my code to not run every frame?
Attack Cooldown
If I press down arrow, I want the collider2d to be disabled for 0.5 seconds then be repeatable.
Time since camera moved/player inactive
Half of a script is not read anymore after reloading the scene
Need help making gun reloading time.
Stopping a function in a script when i recall it.
How do I implement rapid firing into my pistol?
I can't stop my coroutine.
New to Unity, having issue with Line Renderer
Time in between action (dash)
Reset Timer on Trigger?
Attack 2 enabled collider appears before Attack 1 disabled collider Causes Attack 2 collider Enable to be missing
Does unitask/async make sense over simple deltatime timer for cooldowns etc
Rapid Fire With Input System
How to implement Attack Interval? by Awaitable Class?
Giving a boost to a character
Trying to add delay to my turret to fire after it instantiates (10 seconds)
Changing colors via script
How do I make a wait code in script so when I walk it waits and plays audio for footsteps?
Change color and glow for a while
Hotbar button shading flickering
UniTask based Debounce Method Help
Recreating Space Invaders for my University project, need help with enemies shooting randomly.
Ability Cooldowns
Can anyone tell me how can i make this shooting script auto?
How should I loop a coroutine like this?
NullReferenceException (946744)
Speed Changing Power-Up With Speed Controlled in Update Method of PlayerController Script?
I Want to Disable the X Key for 2 Seconds When I Press "Space"
Can't instantiate several bullets in a row
Two conditions for bool
Coroutine yields to a cooldown only once, what am I missing?
Time delay isue
Please I need help making delay between shots!
Need Help with Play.OneShot()
AddForce for a fixed time
HoldToRepeat function in input System
Unintended Coroutine Interactions?
Restart timer
Countdown timer for different areas (917116)
Check time between shots
Multiple mashes problem
Count down timer, reset bug
Scripting an in-game Timer
When I start a coroutine by clicking on a button, does everytime i click it again, starts a new one?
Why is this script freezing unity?
Trying to put multiple guns on an aircraft creates weird behavior
I would like to know if this script is well written.
How to make a wait timer?
2D Platformer - Stop While Attacking
I have trouble making raycast work with tag.
How to add dash cooldown?
What can I do about this atrocious IEnumerator script?
How to extend coroutine triggered by event
Help with Input System + holding key + coroutine behaviour
I need help with my 2D movement
How do I reset a countdown timer every time I exit out of a collider which sets off the countdown?
I want to heal taking damage, but I don't know how to reset the wait time upon taking more damage.
Replenish Stamina coroutine
Attack Timer Out of Wack
New Guy: How to make a character have "needs" on a timer?
Instantiated Bullets Teleport When Shot
How to add delay before button can be pressed / code is executed again.
how do i limit the amount of times the player can excecute the shoot command
Attempting to code a simple healthpack powerup
How: Game Object Handler
NPC-AI Random Behaviour System doesn't work, need urgent help
Why does unity keep freezing?
Random.Range() doesn't work
Bug in my code that may be used as a sprint "hack"
Disappear button when clicked for 2 seconds
The enemy's random attack move
How do I add a delay in Update()?
How to implement time delay in damage (Invincibility Frames)
Need a simple way to have the space bar have a cooldown so you cannot spam it!
invoke within a if statement