Saving data between scenes using static properties
Keeping track of the player’s progress and user settings during a game is vital to give your game a greater feeling of depth and content. In this recipe, we will learn how to make our game remember the player’s score between the different levels (scenes).
Note that this example game is rigged! In this game, higher will always win, and lower will always lose, but we can build on this simple game to count, store, and retrieve the number of wins and games that have been played.
Figure 10.1: Our Higher or Lower game, with the score being remembered between scenes
Getting ready
We have included a complete project in a Unity package named game_HigherOrLower
in the 10_01
folder. To follow this recipe, we will import this package as the starting point.
How to do it...
To save and load player data, follow these steps:
- Create a new Unity 2D project, and import the
game_HigherOrLower
package...