public void SaveLevelData(string levelName, int starsNumber) { LastLevel = levelName; if (!LevelData.ContainsKey(levelName)) { LevelData.Add(levelName, starsNumber); } else { //Player collected more starts than the first time if (starsNumber > LevelData[levelName]) { LevelData[levelName] = starsNumber; } } var jsonLevelData = JsonUtility.ToJson(LevelData); PlayerPrefs.SetString("Levels Data", jsonLevelData); PlayerPrefs.SetString("Last Level", LastLevel); }