Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- public class Registry : MonoBehaviour {
- public static Registry Instance { get; private set; }
- public static object lockObject = new object();
- public PlayerData player;
- public class PlayerData {
- public int level = 1;
- public int hp = 100;
- }
- public TransitionData transition;
- public class TransitionData {
- public string targetScene;
- public Vector3 targetPosition;
- public float targetRotation;
- }
- public void Awake() {
- lock (lockObject) { // probably don't need this unless we accidentally add 2 registrys to scene
- if (Instance == null) {
- transform.parent = null; // must be a root object to be persistent
- DontDestroyOnLoad(this);
- Instance = this;
- Initialize();
- } else if (Instance != this) {
- Destroy(gameObject);
- }
- }
- }
- private void Initialize() {
- player = new PlayerData();
- transition = new TransitionData();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement