Unity Game Development Saving & Loading using PlayerPrefs
Class overview Class 5 Revision Introduction to Mixamo.com Setting up Player Setting up Enemy Setting up Collectibles Singleton - Coding Design Pattern Serialization of Data Saving Loading Advanced: Checkpoint System
Revision Third Person Camera Player Movement Camera Movement Camera Rotation Camera LookAt Camera Zooming Importing Assets Animation BlendTree Advanced: Animation events Advanced: Contextual sound using Raycasting
Introduction to mixamo.com Register Adobe account Preview & Select Characters Preview & Select Animations Download & Import .FBX to Unity
Setting up Player Create PlayerLogic (Movement, Jumping, …) Create AnimatorController (Idle, Walk, Run, Jump) Setup BlendTree (Add parameters) Set Animation Parameters from Code
Setting up Enemy Create EnemyLogic (Movement, Distance checking, States…) Create AnimatorController Setup BlendTree (Add parameters) Set Animation Parameters from Code
Setting up Collectibles Create CoinLogic (Rotation, OnTriggerEnter,…) Advanced: Update UI on collection
Singleton - Coding Design Pattern Singleton = There can only be one of it’s type, can be accessed from anywhere. Examples of Singletons: GameManager, UIManager, AIManager, MusicManager, LocalisationManager, … “In software engineering, the singleton pattern is a software design pattern that restricts the instantiation of a class to one "single" instance. This is useful when exactly one object is needed to coordinate actions across the system. The term comes from the mathematical concept of a singleton.”
Serialization of Data Savable Datatypes: Int, Float, String Vector3 cannot be saved Vector3 = 3 x Float (Pos X, Pos Y, Pos Z) Enums cannot be saved Enum = Int
Saving PlayerPrefs.SetFloat("PlayerPosX", transform.position.x); PlayerPrefs.SetFloat("PlayerPosY", transform.position.y); PlayerPrefs.SetFloat("PlayerPosZ", transform.position.z); PlayerPrefs.Save();
Loading float playerPosX = PlayerPrefs.GetFloat("PlayerPosX"); float playerPosY = PlayerPrefs.GetFloat("PlayerPosY"); float playerPosZ = PlayerPrefs.GetFloat("PlayerPosZ"); transform.position = new Vector3(playerPosX, playerPosY, playerPosZ);
Checkpoint system OnTriggerEnter Save Data OnDeath Load Data from Last Checkpoint
Q&A Do you have any questions related to the topics mentioned?