This example demonstrates how you can save the last scene the player entered, and reinsert them into that scene when loading.
This does not save the contents of the scene, only the name of the scene so that they can be reinserted into it. For saving and loading the contents of a scene, please see examples such as this one:
IMPORTANT: For this example to work, you need to add MainMenu, Scene1, Scene2 and Scene3 to the 'Scenes in build' section of File > Build Settings.
The project works as follows:
- You begin in the Main Menu.
- The 'Start New Game' button deletes any existing save data and loads the first scene of the game.
- The 'Load Game' button loads the last scene that the player was in. If there's no save data, this button is hidden.
- When you press 'Start New Game', you will enter Scene1.
- The 'Go to next scene' button takes you to the next scene in the game.
- The 'Save scene' button gets the name of the current scene and saves it.
- The 'Go to main menu' button takes you back to the main menu.
- Scene2 and Scene3 are the same, except Scene3 does not have a 'Go to next scene' button.
- The key field on all of your Save and Load actions should be the same. For this example we use the word "CurrentScene" as the key.
- Instead of having a save button you could instead get it to save in the Start event, depending on what you want to achieve with your project.