Cool Down system in Unity
When a player fires a laser using any keys , there is a continuous stream of bullets as we see below.
It gives advantage to the player so the user experience with the attack will be low. So to increase user experience and to create enemies of
equal strength , we create a cool down system in games where the user cannot fire continuously and some time intervals will be given between the keypresses to enhance
user experience.
Laser Script
Let us create a cool down system
Lets us create a variable _fireRate=0.5f and _canFire=0.0f
for every half second I want to fire a bullet , so my _fireRate is 0.5f , you can change the values according to your need.
so when can I fire ,what is condition for firing ? In the first case let assume _canFire=0.0f
so when the space key is pressed and Time.time > _canFire , at this time let say Time.time is 1 second
so now you can test ..though you have urge to fire a bullet , you have to wait for your time and this user experience is enhanced.