Platformer: Resetting the Level

Ryan McCoach
2 min readSep 5, 2021

Introduction

In this quick article, I will cover how to reset or restart a level. In this example, when the player is out of lives the level will automatically reset. This technique to be used with input, like if the R key is pressed then restart the level.

The Code

We will need access to the Scene Management library, so we can load different or the same scene.

In our Lose Life method, we want to check if the player’s lives is less than 0 then we will access the SceneManager and call LoadScene method. We will have to pass in the scene index we want to load. Currently, this is the only scene so the index is 0.

This is a small feature and is something mostly never thought about when playing games, but as a game developer is expected to put incorporated in games in some fashion.

Keep Coding & Cheers!

--

--