Cooldown System

Al Heck
May 13, 2021

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.

--

--

Al Heck

Unity Developer and Software Engineer who loves making games with GameDevHQ