How do I save custom variables?
Hi, I'm working on a save and load system for my game. The basics like position is simple, I just have
public void Save() {
PlayerPrefs.SetFloat ("X", transform.position.x);
PlayerPrefs.SetFloat ("Y", transform.position.y);
PlayerPrefs.SetFloat ("Z", transform.position.z);
}
public void Load() {
float x = PlayerPrefs.GetFloat ("X");
float y = PlayerPrefs.GetFloat ("Y");
float z = PlayerPrefs.GetFloat ("Z");
transform.position = new Vector3 (x, y, z);
}
And it does work flawlessly.
Now, I want to save variables like Health, Experience and PlayerLevel, which are all custom variables. Here's the code I have in another script:
[SerializeField] private Stat health;
public static Stat Health { get; set; }
[SerializeField] private Stat exp;
public static Stat Exp { get; set; }
[SerializeField] private Stat oxygen;
public static Stat Oxygen { get; set; }
[SerializeField] private Stat playerLevel;
public static Stat PlayerLevel { get; set; }
Now here's my question, how do I reference those Stat values? Do I need to convert them to ints or floats somehow?
Comment
Best Answer
Answer by Jarzyna · Nov 19, 2016 at 06:10 PM
Uhh, it was kinda dumb really. All I needed to do is use, in case of Health as an example. Health.CurrentVal which is just a float value and it works.