The GameSaver component allows you to save and load games to PlayerPrefs without writing any scripts.
To use this component:
- Add the component to a GameObject.
- Set the Player Prefs Key (i.e., saved game slot) where the game will be saved and loaded. To make multiple slots, you can add more GameSaver components to change the Player Prefs Key field in each.
- To save a game, send the message "SaveGame" to this component. You can use a GUI Button or Send Message On Dialogue Event trigger to send the message, or call the component's
SaveGame()
method from a script.
- To load a game, send the message "LoadGame" to this component (or call it from a script).
- To restart the game, send the message "RestartGame" to this component (or call it from a script).
- To record the state of the game without saving, for example when changing levels, send the "Record" message.
- To apply the saved state of the game, for example when returning to a level, send the "Apply" message.
- You can also configure this component to save or load when the player "uses" the GameObject – that is, when the GameObject receives an "OnUse" message. To do this:
- Set Function On Use to Save or Load. This tells the component whether to save or load when it receives an OnUse message.
- Send the message "OnUse" to this component or game object. For example, the Selector component sends OnUse when the player hits spacebar over the object.
- If you tick Apply Game State When Loading Levels, then this component will automatically apply the recorded game state as soon as the level is loaded. You're responsible for issuing the "Record" message before loading the level, in order to record the state of the level being exited.
If the GameSaver and LevelManager component are both on the Dialogue Manager object, then the GameSaver will use the LevelManager.LoadGame() method, which also loads the player's current level.
GameSaver calls PersistentDataManager.LevelWillBeUnloaded()
for you.
<< Persistent Data Components | Persistent Data Manager >>