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 start up, 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; using UnityEngine.SceneManagement; using UnityEngine; //------------------------------------------------ public class LevelSaveRestore : MonoBehaviour { //------------------------------------------------ [SerializeField] int LastAchievedLevel = 0; string LastAchievedLevelName = string.Empty; public int CurrentLevel ...