Respawning the player

2D Game Design with Unity

🕑 This lesson will take about 14 minutes

In this lesson, you will learn how to write code that will make the player respawn in the game, for example, when the player falls below the platforms. At the start of the game, the player’s position will be stored in a variable. When the player dies, the position of the player will be set back to the original location stored in the variable. The code to implement respawning will be added to the existing script we have worked on throughout the lessons in this course called ‘PlayerController.cs’ (scroll down for the sample code).

Game art, tiles and sprites from the Free Pixel Space Platform pack are used in this lesson video and can be downloaded from the Unity Asset Store.

Is YouTube blocked at school? Watch on Google Drive.

Sample code

Next lesson: Respawn checkpoints