Cooldown System

Let’s create a cooldown system in C# using coroutines.

The easiest way — in my opinion — to implement a cooldown system would be through the use of a bool. Let’s check the timer, set it to false, if the timer goes past a certain point, set it to true.

The simplest way is through a coroutine, which initializes through a IEnumerator. We add a float value of _fireRate of 0.5f. After 0.5f, it will turn the weapon to true.

When we start the game, we set _canFire to true. After we fire our first bullet, we then instantiate our bullet, turn _canFire to false, and then run the coroutine. At the end of 0.5f, it turns true again and we can begin firing weapons all over again.

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
Al Heck

Unity Developer and Software Engineer who loves making games with GameDevHQ