public void SaveHighscore() { BinaryFormatter bF = new BinaryFormatter(); FileStream file = File.Create(Application.persistentDataPath + "/highscores.dat"); SaveDataHighScore data = new SaveDataHighScore(); data.highscoreLevel1 = highscoreLevel1; bF.Serialize(file, data); file.Close(); }
public void LoadHighscore() { if (File.Exists(Application.persistentDataPath + "/highscores.dat")) { BinaryFormatter bF = new BinaryFormatter(); FileStream file = File.Open(Application.persistentDataPath + "/highscores.dat", FileMode.Open); SaveDataHighScore data = (SaveDataHighScore)bF.Deserialize(file); file.Close(); highscoreLevel1 = data.highscoreLevel1; } else { highscoreLevel1 = new HighScore[] { new HighScore("Benedict Cumberbatch", 0), new HighScore("Benerec Cumbersnatch", 0), new HighScore("Fenedict Slumberwitch", 0) }; } }