- Home /
Why don't my Save and Load button work
When I change a scene and come back from that scene to main menu my Load and Save Buttons don't work.
public void Save()
{
Debug.Log (Application.persistentDataPath);
BinaryFormatter bf = new BinaryFormatter ();
FileStream file = File.Create (Application.persistentDataPath + "/playerInfo.dat");
PlayerData data = new PlayerData ();
data.health = health;
data.agility = agility;
data.strenght = strenght;
data.skillpoints = skillpoints;
data.attribiutepoints = attribiutepoints;
data.expirience = expirience;
bf.Serialize (file, data);
file.Close ();
Debug.Log("Saved");
}
public void Load()
{
if (File.Exists (Application.persistentDataPath + "/playerInfo.dat")) {
BinaryFormatter bf = new BinaryFormatter ();
FileStream file = File.Open (Application.persistentDataPath + "/playerInfo.dat", FileMode.Open);
PlayerData data = (PlayerData)bf.Deserialize (file);
file.Close ();
health = data.health;
agility = data.agility;
strenght = data.strenght;
skillpoints = data.skillpoints;
attribiutepoints = data.attribiutepoints;
expirience = data.expirience;
Debug.Log ("Loaded");
}
I tried loading scene by SceneManager.LoadScene and Application.LoadLevel
Comment
Your answer
Follow this Question
Related Questions
How to get the button Working? 2 Answers
How can I intercept "Play scene" event at code? 1 Answer
Move camera upon button press 0 Answers
I can't click to an UI button. 3 Answers