Everdevs Community
Published in

Everdevs Community

“Funslingers” Devblog #3 | Creating a Cooldown System in Unity

Hey Devs!

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!

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!

--

--

--

Game dev tutorials and news about Everdevs.

Recommended from Medium

How to Delete a Git Branch — Locally and Remotely?

How to Delete a Git Branch — Locally and Remotely?

Mtg Dmg Is On Left Or Right

How to Dynamically Scrape Multiple Amazon Products Pages Using BeautifulSoup?

Define a Static IP Address for a Device or Machine in a Linux Environment

CSS GRID

Big Data Saving You From Catastrophic Success

Don’t waste your money. Keep your GCP budget.

Basic SQL For Data Analysis

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ethan Bristowe

Ethan Bristowe

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

More from Medium

Getting Starting with the DFRobot 2.2 Inch Round TFT Display using an Arduino Mega 2560

The never-ending fight with quantization

Seven multiplayer talks you need to see at GDC

Tri-Mesh Subdivision Based on Specific Triangle Criteria