Saving data for Dead Keys

For Dead Keys, our level loading needs are simple, technically. We simply need to save the latest level we have reached and then restore back to the beginning of that level every time the game is started. To do this, we can use the Player preferences class. Create a new script, named LevelSaveRestore.cs:

Creating a new save state script

This script file should be attached to one, and only one, empty object in the scene, which is active at level startup, and this should happen for every playable level in the game. The full code for the script file is shown as follows:

using System.Collections; using System.Collections.Generic; ...

Get Mastering Unity 2017 Game Development with C# - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.