Book Image

Mastering Unity 5.x

By : Alan Thorn
Book Image

Mastering Unity 5.x

By: Alan Thorn

Overview of this book

Mastering Unity 5.x is for developers wishing to optimize the features of Unity 5.x. With an in-depth focus on a practical project, learn all about Unity architecture and impressive animation techniques. With this book, produce fun games with confidence.
Table of Contents (16 chapters)
Mastering Unity 5.x
Credits
About the Author
Acknowledgment
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

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 =...