public void SaveHighScores(string name, int level, int points) { HighScores = LoadHighScores() ?? new HighScores(); if (HighScores.HighScoresList.Count > 4 && HighScores.HighScoresList[4].Points > points) { return; } HighScores.HighScoresList.Add(new HighScore { Name = name, Points = points, Level = level }); HighScores.HighScoresList = HighScores.HighScoresList.OrderByDescending(score => score.Points).ToList(); if (HighScores.HighScoresList.Count > 5) { HighScores.HighScoresList.RemoveAt(5); } File.WriteAllText(Application.persistentDataPath + "/highscores.json", JsonUtility.ToJson(HighScores, true)); }
public HighScoresController() { HighScores = new HighScores(); }