Creating a Cool down System

PieceofPhie
2 min readMar 24, 2021

Previously, I made a firing script for my prototype that spawns capsules when i push space bar. You can mash away at space bar and spawn as many bullets as you want. Its not particularly a bad thing, but I like to have a delay between shots for this design. So well be creating a ,’Cool Down System’.

we’ll be working with three things, Time.time, a Firerate float variable, and a Canfire float variable.

Whats going to happen is that we will have the script compare the current game’s uptime to a Canfire float variable of -1 in the same If statement of our spacebar input. Then having Canfire equal to Time.time(current seconds) plus Firerate nested within the If statement. Making our If statement return false until time.time is greater than or equal to Canfire.

So if the game ran for one second without pressing spacebar. Time.time will equal to 1. Pushing spacebar will satisfy the If statement since Canfire will initially equal -1 and we are indeed pushing spacebar.

1 is greater than -1 and spacebar is pushed. lets go!

Once space bar is pushed, Canfire will equal to the current seconds + 0.5f(Firerate).

Canfire will now equal to 1.5 and the If statement will return false until our current game time is either greater or equal to 1.5 seconds.

Heres the end result!

its nice and space out in comparison to before and its fully adjustable to my needs.

--

--