Member-only story
Creating a Cooldown System
Yesterday we instantiated and destroyed some awesome cubes for our game. In order to control the timing of the spawns and the destroy to make sure we don’t get overwhelmed with game objects. To do this we used a basic cooldown system.
The system contains a couple of key elements. We have the timer variable that sets the default timer we want our system to use. We decrease the variable using Time.deltatime, so that it properly updates with the update method. Once it reaches 0 or drops below it we dip into the if statement to perform our code and then reset the time.
This is a simple system because it handles a single specific instance for cooldowns. This would be better handled using a coroutine which we will talk about in a couple of days. It might also be helpful to create a more complex cooldown system that can be used by multiple things. For example a spell cooldown system, or a reload timer for an FPS where the reload time differs form gun to gun. Cooldowns give us another tool to slow down the computers processing to give our game more life.
-James