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

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.




Unity Developer — Technology Leader — Making Unity Game Development Look Easy

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

#devlog ## [0.0.1] — 2018–03–08

Lazy Admin — TryHackMe WriteUp

AusHomeLife — My very first Salesforce build as an SF Admin in training (Part 1C).

Lexical Analysis of Source Codes with Walking through Abstract Syntax Tree (AST)

Coding Bootcamps —What are they Like?

Deploying a cloud native Kubernetes dashboard application on Kubernetes

ReactJS frontend + Golang backend REST API application in Kubernetes

How Good Kick-Off Documentation Can Accelerate Your Project

All About Debugging: An Introduction

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
Games Woods

Games Woods

Unity Developer — Technology Leader — Making Unity Game Development Look Easy

More from Medium

How we can heal our relationships? Here are four things you can try

CS371p Fall 2021: Daehyun Kyoung: Final Entry

The Climate Optimist — 18 Oct ’21 — Methane