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!

--

--

Unity and Flutter developer interested in creating mixed-reality applications.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Richard Morgan

Unity and Flutter developer interested in creating mixed-reality applications.