PlayerPrefs highscore system problem

trying to do a playerprefs highscore system, but i think im missing something and cant figure out what it is.

var score : int = 150;

function Start()
{

if( score > PlayerPrefs.GetFloat(“Score1”) ){
PlayerPrefs.SetFloat( “Score5”, PlayerPrefs.GetFloat(“Score4”) );
PlayerPrefs.SetFloat( “Score4”, PlayerPrefs.GetFloat(“Score3”) );
PlayerPrefs.SetFloat( “Score3”, PlayerPrefs.GetFloat(“Score2”) );
PlayerPrefs.SetFloat( “Score2”, PlayerPrefs.GetFloat(“Score1”) );
PlayerPrefs.SetFloat(“Score1”, score);
}
else if( score > PlayerPrefs.GetFloat(“Score2”) ){
PlayerPrefs.SetFloat( “Score5”, PlayerPrefs.GetFloat(“Score4”) );
PlayerPrefs.SetFloat( “Score4”, PlayerPrefs.GetFloat(“Score3”) );
PlayerPrefs.SetFloat( “Score3”, PlayerPrefs.GetFloat(“Score2”) );
PlayerPrefs.SetFloat(“Score2”, score);
}
else if( score > PlayerPrefs.GetFloat(“Score3”) ){
PlayerPrefs.SetFloat( “Score5”, PlayerPrefs.GetFloat(“Score4”) );
PlayerPrefs.SetFloat( “Score4”, PlayerPrefs.GetFloat(“Score3”) );
PlayerPrefs.SetFloat(“Score3”, score);
}
else if( score > PlayerPrefs.GetFloat(“Score4”) ){
PlayerPrefs.SetFloat( “Score5”, PlayerPrefs.GetFloat(“Score4”) );
PlayerPrefs.SetFloat(“Score4”, score);
}
else if( score > PlayerPrefs.GetFloat(“Score5”) ){
PlayerPrefs.SetFloat(“Score5”, score);
}
highscore();
}

function highscore()
{

guiText.text = (PlayerPrefs.GetFloat(“score1”)).ToString ();
guiText.text = (PlayerPrefs.GetFloat(“score2”)).ToString ();
guiText.text = (PlayerPrefs.GetFloat(“score3”)).ToString ();
guiText.text = (PlayerPrefs.GetFloat(“score4”)).ToString ();
guiText.text = (PlayerPrefs.GetFloat(“score5”)).ToString ();

}

It would be simpler to use an array, and ArrayPrefs2. Also, http://forum.unity3d.com/threads/143875-Using-code-tags-properly

–Eric

Well you do not say what is wrong… But do you check score at the start of the game only? Else they should not be in the Start method. Also do you initialize scores somewhere?

Firstly you don’t say what the problem is. Secondly your score is an int and you are saving it as a float. Thirdly computers are your friend, never use 100 lines when one line could do. Follow Eric’s advice, use an array and then sort it once you add the new score in. in your display function use a loop, loops are good!

Oh and you can’t call GUI functions from the start function, you need to put that lot in an OnGUI function.

Thanks for the reply’s, ill try Eric’s advice :slight_smile:
i’m new to javascript :slight_smile: