Easy Cooldown System In Unity

Coroutines give us the power to easily implement logic for waiting a certain amount of time. This is perfect for a cool down system. Let’s take a look.

First we need a control variable to handle when we can and can’t fire.

We also need a variable to determine how long our cooldown period will be.

Now, in Update() when we are checking for laser fire input, we can also check to see “_canFire” is true.

If we’re able to fire, we immediately set that bool to “false” so it will only run once until our bool is set to “true” again.

Now, for the main cooldown logic. We’ll use a coroutine to wait “cooldownTime” seconds and pass that in as a parameter to the coroutine.

There we go. A simple, yet flexible cooldown system in just a few mins.

--

--

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
Chandler Lane

Chandler Lane

Unity Developer - Professional Actor