Creating Lives System

Limiting the amount of deaths available for the player

Time to add in another functionality to our barebones prototype 2.5D platformer. The lives functions basically keeps track of how many times the player can screw up before a hard game over occurs.

Scripting Lives:

Similar to how to script the score system and how it updates the values to our UI manager. We can essentially follow the same structure to create the Lives system.

We start by creating the handle and value of the Lives in the player script by defining the integer value and given name. Then we create an new public method called “Damage” or whatever you desire, and place in the following code.

As you can tell, it is exactly the same as the score method, the only difference is, instead of adding say lives, we are going to be substracting them with an “minus minus”.

In the UI Manager script, we are going to update the text element of the UI whenever our player falls into oblivion and substract 1 live.

Even thought we say the text Lives is + the integer value of Lives, since we are minus on the player script, it will still count as a negative.

The beauty of the script is that it is very simple to understand and incorporate.

Finally, within the Player script again, we are going to define the max amount of lives within the Start Method. We reference the UI Manager script and call upon the public “Update Lives Display” method and give the integer value a number which will equal our total lives.

Back in Unity, you will see that the Lives value will update to the set total amount upon playing.

Once the game starts, the Lives value should update to our set total.

A Designer, an Illustrator and a massive tech geek aspiring to become a professional Unity Developer.

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

Recommended from Medium

How to get around of the “UnicodeEncodeError: ‘utf-8’ codec can’t encode character …: surrogates…

Did you forget something?

NoSQL Injection in Kadira

ISTIO and smallstep CA — automatically create a certificate and configure a mutual ISTIO ingress…

Introduction To CodeCast

Control flow and Common Control Structures in Go

waterfall

Enemy Script Optimization

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
Simon Truong

Simon Truong

A Designer, an Illustrator and a massive tech geek aspiring to become a professional Unity Developer.

More from Medium

Creating a Loot System (part 2)

3rd Person Controller Using Cinemachine Virtual Camera On Mobile

USING GAMEOBJECT ARRAY FOR SPAWN MANAGER

Simple Player Movement