Creating A Cooldown System in Unity
Controlling the fire rate in Unity is easily done by comparing Time.time (the number of seconds that have passed since the game began) with a time increment of a specified value.
Here’s the Unity documentation of Time.time:
https://docs.unity3d.com/ScriptReference/Time-time.html
First we create the fireRate and canFire variables. fireRate will be the maximum fire speed and canFire will store the current Time.time plus the fireRate. If Time.time is less than canFire, in other words the fireRate time has not passed, then the FireLaser method can not run.
Pretty simple, right!