- Home /
Organizing Player Prefs?
Hello. I want to have a local high score screen. If I am setting the score variable using this script:
function Update () {
var myScores = new int[R_Player.SCR];
for (i = 0; i < myScores.Length; i++)
myScores[i] = i+1;
}
How do I then display the scores in the GUI and organize them from greatest to least (you know, like a normal high score screem where the highest score is at the top, lowest at the bottem, etc.).
Answer by Jesse Anders · Feb 01, 2011 at 02:02 AM
To get them in order, I'd use one of the 'sort' functions provided by the .NET library. Presumably you'll want to associate a name or something with each score, so you'll probably want to store a custom data type that stores the score and the corresponding name; then, you can sort them using a custom comparator. (I don't know the details in UnityScript unfortunately.)
Once you have them sorted, you can display them (for example) using calls to GUI/GUILayout.Label() in a loop, with the y coordinate of the rect for each label computed from the loop index.