Reloading Now- Game Dev Series 22

Objective: Make a reloading function when game over.

Previous: It’s Time to Game Over

We got game over now and nothing we can do when this happened.
We should add a restart function to it.

Add an image game object as what we did in the previous articles.
Set the location and size, set the overflow method, and typing the text.

Also, make a variable of Restart_text and set it default as disable in the void Start().

Then set it active when the lives count is 0.

It should shows up when player is game over.

Next we need to make the ‘R’ key actually works.

To reload, we need to use an Unity system called SceneManagement.

Create another game object called Game_Manager in the root of hierarchy. This will be the main part to handle the scene reload.
Create a C# script called GameManager and attach it to Game_Manager. Inside GameManager, we will add the Unity package at the top of script.

In the Update(), we want to reload the game when we press ‘R’.
Add an if statement to reload the scene.

Before we create the line to reload, we should check the scene in Unity.
Back to Unity, select from the dropdown menu File> Build Setting…
Click Add Open Scenes and you should get the current scene name and index.

Now the Unity actually get the scene. We can add a line to it.

We use SceneManager.LoadScene() to reload. LoadScene() can pass in integer or scene name.
In this line, we use SceneManager.GetActiveScene().buildIndex to get the current scene index as the integer.

However, so far we can press R to reload the scene anytime because we have not detect if Player game over or not.
We can create a bool to this situation and create a method to set it true.

Back to UIManager, let’s add a variable and call the method when lives count is 0.

You can add a null check to prevent error.

Back to GameManager, add the bool check in the if statement.

And you can reload the game when you run out of lives.




A passionate gamer whose goal is to work in video game development.

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

Recommended from Medium

How to Restore Deleted BigQuery Tables

Delete key on a keyboard.

Building Spazi experience

Playing with Oracle ASM, multipath disks, TrueNas and VirtualBox — Part 2

An Indepth Guide to HTML Forms

How to Git in Unity- part 3

A Taste of PyTorch C++ frontend API

CS373 Spring 2021 Final Blog: Regina Chen

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
S.J. Jason Liu

S.J. Jason Liu

A passionate gamer whose goal is to work in video game development.

More from Medium

Day 105: Working with Animation Events in Unity

My Optimal Scene & Project Unity Layout

What is a Control Track in Timeline

Learn to code by making 2 D space shooter.