Creating a cooldown system in Unity
Mar 27, 2021
When shooting, it is good to create a cooldown system, so the player can shoot the laser after a time delay
Time.time is the time passed since the game began
Let’s create 2 float variables and 2 conditions in Update
When Time.time = 5f and space key is pressed, both conditions are true, so the player can shoot a laser
After that, we set the canFire value to Time.time + fireRate, so canFire = 5.7f This way, the player needs to wait until Time.time = 5.8f to shoot again
FireLaser method to be called in Update
Without cooldown system
With cooldown system