And…..Scene! Loading Scenes in Unity

Photo by GR Stocks on Unsplash

We’ve implemented our Game Over text when we’ve run out of lives but we want the player to be able to restart the game. Let’s do this!

First off we’ll create a new Text Element in the Canvas that gives the user the instructions on how to restart the game by pressing the R key.

Next it’s good practice to create a Game Manager for you game to handle these types of actions. Create an empty Object and call it Game_Manager. Next in your script folder create a corresponding new script called GameManager. You’ll notice that Unity gives it a gear icon. So it knows it’s a thing :) Drag it onto your Game_Manager Object

Next we have to script the behavior in our game manager. We start by declaring the use of UnityEngine.SceneManagment. We’ll also create a variable to set when the GameOverSequence is called on….you guessed it when the game is over!

In our update method we will check for the R key and the _isGameOver state to be true and when those two conditions are true we will use the SceneManage.LoadScene(1) to reload our Game Scene. (the 1 is an index of all of a games scenes and they can be reviewed by going into Build settings and checking for their index number).

And just like that we’ve reloaded our scene. All our lives are reset as well as our score starts from 0 again.

Next up we will make things go boom when we create enemy explosions when they are hit. Until then…Adios!




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

Kops multiple Ingress resources Together with a single Application Load Balancer — let's get rid…

Udemy Course: Learn Professional C++ | Using Custom Libraries

creating notifications through Alerting / Watcher X-Pack plugin on Elastic Cloud — Part 1

CloudFormation Custom Resources — Best Practices

Basics of Python.

Let’s create a continuous integration and continuous deployment (CI-CD) with Azure DevOps

How I convert myself from a buyer to a web developer in six months

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

Saving Data in Unity3D Using Files

Script communication in unity using GetComponent:

What is Filebase and How do you use it?

Upgrading to the Universal Render Pipeline (URP)