So I have this save method:
void Save()
{
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Create(Application.persistentDataPath + "/playerinfo.dat");
PlayerData data = new PlayerData();
data.score = score;
}
And a load method:
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();
score = data.score;
}
}
and a PlayerData class:
[Serializable]
class PlayerData
{
public double score;
}
All of that seems to work quite fine. It works fine after building. But if I want to another variable that needs to be saved for example data.time then after building and starting the game again the file seems to be broken and it does not load correctly what was saved before and does not save the new variable. Why is this happening and how can I avoid that?
Greets Speedy