Adding new HighsScore into ordered Array
I am trying to save my new score into my Top Ten highscores and dismiss the eleventh one. When i try to execute this script in unity, I get an compiler error, but visual studio does not highlights me anything.
//saves PlayerPrefs to array
int[] topTen = new int[11];
for (int i = 1; i <= 10; i++)
{
if (PlayerPrefs.HasKey(i.ToString()))
{
topTen[i] = PlayerPrefs.GetInt(i.ToString());
}
}
//Adds score to array
topTen[11] = score;
//Sorts with score
Array.Sort<int>(topTen);
Array.Reverse(topTen);
//Takes only the top ten elements and saves them back
for (int i = 1; i <= 10; i++)
{
if (topTen[i] != 0)
{
PlayerPrefs.SetInt(i.ToString(), topTen[i]);
}
}
SceneManager.LoadScene("Leaderboard");
Comment