We Need to Chill! Creating a Cool down System in Unity

Games Woods
2 min readApr 29, 2021

Objective: In order to balance gameplay we will implement a cool down system that limits the number of shots a player can fire over a given period of time. This will increase the challenge level and also give us the opportunity to create PowerUp later on.

Implementation: To get started we need to implement a means by which we can keep track of time within the game. Unity has an API for this called Time.time The example provided gives us a good idea of how to implement our solution. First we’ll create two variables _fireRate and _canFire.

We want the player by default to be able to fire their lasers every 0.5 seconds. We’ll make this a serialized field in order to balance gameplay during the polish phase. Next we create a _canFire variable that checks against Time.time +_fire Rate variable to see if the player can fire.

In out Player.cs script we simply need to update the existing firing code so that the logic include that GetKeyDown AND (&&) Time.time element to be greater than the _canFire variable value.

Once we save our script and do a play test we see that we’ve successfully implemented a more reasonable “cooled down” firing rate. Adjust to your liking.

--

--