Learn to code by making a 2.5 D space shooter game.

Suleiman Abdullah
3 min readJan 11, 2022

Objective: add Restart info Text and Reload the scene when R is pressed.

The first step I to create a text component rename it Restart text.

Increase the size of the font, change color to white then snap it to the bottom of the screen.

Now disable the restart text object by default when the game start.

To enable the text we need to create a variable of the game object inside IUManager.

Drag the restart text object to a field in the UIManager script which is attached to canvas GameObject.

Create a method to enable restart text and call it when we check the player if he is dead.

calling restart method.

Last to check if we press the R key, if we press the R key we reload the level.

Note: To check the input, we did through Update since this function is a game loop we need to check if Input is pressed for the life of the program within every frame.

we pass index 0 cos scene count by index start from 0 to upward and we only have 1 level

In order for the scene to be loaded, you need to add it to the build setting.

If your IntelliSense is not showing “SceneManager.LoadScene” you need to include “using UnityEngine.SceneManagement”.

Or

Note: the best Practice check input is using SceneManager scripts, implement all logic here.

Create a bool variable to check if game over is true and its method called Game over which turns the isgameover bool to true.

Now create the Update method inside GameManager to check the input and check if Gameover is called from UIManager to load the scene.

Go to UIManager create a handle assign the handle to the component then call this method when Player Lives is zero.

Choose the best path!

--

--

Suleiman Abdullah

Self taught Unity Developer, who is passion about making games ,and he loves Math For Game Development