Nerd For Tech
Published in

Nerd For Tech

Creating Basic Game Over Behaviour

Game Over

To demonstrate how you can easily start using the Image UI Element through code, in this article we’ll be looking at creating a basic Game Over system.

The idea is very simple, by code we declare that the ‘Game Over’ Image is turned off by default and if needed, we turn it on. You can apply this to any image for your own project.

In the UIManager.cs Script, create a new private member variable allowing us to reference the Image Element through code, just like we did for the Text Element.

Assign your ‘Game Over’ Image in the Inspector

Now let’s have a look at this function;

  • Value: Activate or deactivate the object, where true activates the GameObject and false deactivates the GameObject.

In the Start() Method we can use it to disable the Image at first by saying:

Then we could create a new Method that we can access later, to enable the Image:

Enabling the ‘Game Over’ Behaviour

Moving to the Player.cs Script, first thing we do is create a reference to the UI Manager (if you haven’t already), this is needed to communicate through scripts:

Now in the TakeDamage(int damage) method, we can tell the UI Manager the Game is Over when the Player dies.

Great, the basic ‘Game Over’ Behaviour is now functional. Except let’s think a step ahead; knowing that we’ll be upgrading and adding more features to the UI functionality later, we could attach it to a new parent called the ‘Game Over Window’, and turn that on and off instead:

In the following article we’ll continue to improve the UI and introduce a Health Bar for the Player.

Previous | Next




NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit

Recommended from Medium

What is InsureDao

How to get around “RuntimeError: This event loop is already running”


Hologen Platform 2.5: Better, faster, stronger!

My take on programming languages

READ/DOWNLOAD@> Questions of Perception: Phenomenology of Architecture FULL BOOK PDF & FULL…

7 Simple Attributes of Good Code

How to identify attributes of good code

Enemies: Creating the Astroid behavior | Unity 2D

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
Gert Coppens

Gert Coppens

Software Engineer — Unity Game and Application Developer

More from Medium

Cleaning up the Homing Missile code

Creating MineField In Unity (Part 2)

2D Mobile: Setting Up The Player

Take Photo with Phone in Unity