Western Shooter Devblog #3 | Creating a Cooldown System in Unity

Ethan Bristowe
2 min readApr 28, 2021

--

As we saw in my last Devblog, Cubert has a bit of a trigger finger. He’s able to shoot as fast as the player is able to press the spacebar, that can cause a lot of problems in term of game-design, balancing, and the sneaky players that know how to use macros. So let’s fix that!

Last time, we used a Coroutine for creating a a destroy timer on the bullets. This time we’re actually gonna use a different timer method for our rate of fire cooldown system!

So currently, firing Cubert’s gun can look like this:

That’s no good, we don’t want the player to be able to spam it like it’s machine gun, so to make this cooldown system all we need is a little bit of Time…

Time.time to be precise.

All I did was add a second parameter to our if statement, once the first fire is shot, it will grab the current Time.time of the game runtime, add the desired fire-rate variable to it, and then make it a requirement for the current Time.time to pass that new number.

We serialize the field so that I can adjust the fire-rate in the inspector for fine-tuning without needing to go back into the script.

I’m spamming the spacebar as quickly as I can here fyi

Look at that! I can now control the speed at which the player is allowed to shoot their gun!

In the next Devblog we are gonna add enemies and use physics to shoot them! How exciting!

--

--

Ethan Bristowe
Ethan Bristowe

Written by Ethan Bristowe

Passionate self taught game developer excited to learn and share everything I can about game development!

No responses yet