//[SerializeField] privatestatic HighScoreTable_Script highScoreTable; // Start is called before the first frame update void Start() { //name = "TES"; score = GameManager.CurrentScore; Debug.Log("In Game over & Score = " + score); TMP_GameOver.text = gameStatusForGameOver; jsonString = PlayerPrefs.GetString("highscoreTableX"); highscores = JsonUtility.FromJson <HighScoreTable_Script.Highscores>(jsonString); for (int i = 0; i < highscores.highscoreEntryList.Count; i++) { for (int j = i + 1; j < highscores.highscoreEntryList.Count; j++) { if (highscores.highscoreEntryList[j].score > highscores.highscoreEntryList[i].score) { HighScoreTable_Script.HighScoreEntry temp = highscores.highscoreEntryList[i]; highscores.highscoreEntryList[i] = highscores.highscoreEntryList[j]; highscores.highscoreEntryList[j] = temp; } } } // Check if the score is greater than any score in Top 10 for (int i = 9; i >= 0; i--) { if (score > highscores.highscoreEntryList[i].score) { Debug.Log("Greater than 1 of the top 10"); HighScoreBool = true; break; } } //Debug.Log("After Sorting"); //for (int i = 0; i < 10; i++) //{ // Debug.Log("New Slot Entry = " + highscores.highscoreEntryList[i].name + " " + highscores.highscoreEntryList[i].score); //} if (HighScoreBool) { HighScorePanel.gameObject.SetActive(true); OkGameOverButton.gameObject.SetActive(false); InputField.characterLimit = 3; } else { HighScorePanel.gameObject.SetActive(false); OkGameOverButton.gameObject.SetActive(true); } }
// Start is called before the first frame update void Start() { if (!PlayerPrefs.HasKey("highscoreTableX")) { Debug.Log("Key not there."); HighScoreTable_Script.Highscores highscores1 = new HighScoreTable_Script.Highscores(); highscores1.highscoreEntryList = new List <HighScoreTable_Script.HighScoreEntry>(); HighScoreTable_Script.HighScoreEntry highscoreEntry = new HighScoreTable_Script.HighScoreEntry { score = 200, name = "ACC" }; highscores1.highscoreEntryList.Add(highscoreEntry); highscoreEntry = new HighScoreTable_Script.HighScoreEntry { score = 300, name = "ACS" }; highscores1.highscoreEntryList.Add(highscoreEntry); highscoreEntry = new HighScoreTable_Script.HighScoreEntry { score = 1475, name = "FBI" }; highscores1.highscoreEntryList.Add(highscoreEntry); highscoreEntry = new HighScoreTable_Script.HighScoreEntry { score = 900, name = "CSI" }; highscores1.highscoreEntryList.Add(highscoreEntry); highscoreEntry = new HighScoreTable_Script.HighScoreEntry { score = 150, name = "WHA" }; highscores1.highscoreEntryList.Add(highscoreEntry); highscoreEntry = new HighScoreTable_Script.HighScoreEntry { score = 1100, name = "THE" }; highscores1.highscoreEntryList.Add(highscoreEntry); highscoreEntry = new HighScoreTable_Script.HighScoreEntry { score = 1750, name = "QUE" }; highscores1.highscoreEntryList.Add(highscoreEntry); highscoreEntry = new HighScoreTable_Script.HighScoreEntry { score = 350, name = "SQL" }; highscores1.highscoreEntryList.Add(highscoreEntry); highscoreEntry = new HighScoreTable_Script.HighScoreEntry { score = 1200, name = "CSS" }; highscores1.highscoreEntryList.Add(highscoreEntry); highscoreEntry = new HighScoreTable_Script.HighScoreEntry { score = 2000, name = "VKC" }; highscores1.highscoreEntryList.Add(highscoreEntry); string json = JsonUtility.ToJson(highscores1); // Save using PlayerPrefs and JSON format PlayerPrefs.SetString("highscoreTableX", json); PlayerPrefs.Save(); } }