public void SaveScore() { string levelDifficuty = GetDifficulty(); var scores = UtilityMethods.LoadPreviousScores(levelDifficuty); var newScore = new ScoresEntry(); newScore.name = PlayerPrefs.GetString("Player"); newScore.score = this.score; var bFormatter = new BinaryFormatter(); var filePath = Application.streamingAssetsPath + "/Saved Data/" + levelDifficuty + "_scores.dat"; using (var file = File.Open(filePath, FileMode.Create)){ scores.Add(newScore); bFormatter.Serialize(file, scores); } }
public void CreateScoresFiles() { string[] difficulties = new string[] { "Easy", "Medium", "Hard" }; foreach (var difficulty in difficulties) { var bFormatter = new BinaryFormatter(); var filePath = Application.streamingAssetsPath + "/Saved Data/" + difficulty + "_scores.dat"; if (!File.Exists(filePath)) { var scores = UtilityMethods.LoadPreviousScores(difficulty); var newScore = new ScoresEntry(); newScore.name = "Master"; newScore.score = 0; using (var file = File.Open(filePath, FileMode.Create)){ scores.Add(newScore); bFormatter.Serialize(file, scores); } } } }