I am trying to create some kind of global class storing player data which could be accessible in the whole project. I created simple singleton using this code:
void Awake () {
if(Instance == null) {
Instance = this;
DontDestroyOnLoad(gameObject);
}
else Destroy(this);
}
Unfortunately only simple variables (like int, string) are acessible. Objects in other scenes are null. What can I do to make them alive just like their simple brothers?
@Edit:
More code:
using UnityEngine;
using System.Collections;
public class PlayerInfo : MonoBehaviour {
public static PlayerInfo Instance;
public string Name;
//string static Password;
public int Money;
public byte Flat;
public byte Gender;
public long CreateDate;
public Skills Skills;
void Awake () {
if(Instance == null) {
Instance = this;
DontDestroyOnLoad(gameObject);
}
else Destroy(this);
}
}
[Serializable]
public class Skills{
public byte dexterity;
public byte vocabulary; // talking skillz
// add more
}
↧