Creating A Cooldown System in Unity

Rusben Guzman
2 min readMay 15, 2021

In this challenge I have a Player that can shoot when I press the space key, the only detail is without any restriction the player can shoot a lot of lasers.

To avoid this overpowering behaviour we should create a cooldown system, in this case after the player shoots we have to wait some time to shoot again.

To achieve this first we gonna create a fireRate variable and a bool canShoot:

Then we gonna create a coroutine in this case will be the cooldown function:

As well we have to add the can shoot variable when we detect the space key:

After create the coroutine we have to call it in the shooting function with the method StartCoroutine:

And that’s it a completely functional cooldown system:

The cooldown system is used in many other games for example Among us have cooldown each time you kill a crewmate as an impostor or in Call of Duty when you receive damage you have to wait some time to heal.

--

--

Rusben Guzman

A Software Engineer passionate about game dev and interactive products with Unity. I consider video games to be the artistic expression of programming.