Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.08 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class Registry : MonoBehaviour {
  4.     public static Registry Instance { get; private set; }
  5.     public static object lockObject = new object();
  6.  
  7.     public PlayerData player;
  8.     public class PlayerData {
  9.         public int level = 1;
  10.         public int hp = 100;
  11.     }
  12.  
  13.     public TransitionData transition;
  14.     public class TransitionData {
  15.         public string targetScene;
  16.         public Vector3 targetPosition;
  17.         public float targetRotation;
  18.     }
  19.  
  20.     public void Awake() {
  21.         lock (lockObject) { // probably don't need this unless we accidentally add 2 registrys to scene
  22.             if (Instance == null) {
  23.                 transform.parent = null; // must be a root object to be persistent
  24.                 DontDestroyOnLoad(this);
  25.                 Instance = this;
  26.                 Initialize();
  27.             } else if (Instance != this) {
  28.                 Destroy(gameObject);
  29.             }
  30.         }
  31.     }
  32.  
  33.     private void Initialize() {
  34.         player = new PlayerData();
  35.         transition = new TransitionData();
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement