Ok in my flappy bird clone i need to make it so it shows 4 scores and 1 high score and show the current score
i have it showing the high score and the last games store using this but how do i save all scoreS?
public int curScore;
// Highest score
private int highscore;
void Update () {
// replace score with new highscore
if (showGameOver && curScore > highscore)
{
// Set the highscore to our current score
highscore = curScore;
// savign highscore
PlayerPrefs.SetInt("Highscore", highscore);
}
}
how can i go about adding in some more scores to sort through
private int score4;
private int score3;
private int score2;
private int score1;
like this?
I think you should set another prefs to save the another score.
public int curScore;
private int highscore;
var secondHigh : GUIText;
void Update () {
// replace score with new highscore
if (curScore > highscore)
{
// Set the highscore to our current score
highscore = curScore;
// savign highscore
PlayerPrefs.SetInt("Highscore", highscore);
}
if(curScore < PlayerPrefs.GetInt("Highscore"))//
{
PlayerPrefs.SetInt("Highscore0",curScore);//save new score
secondHigh.text= "Second Highscore" + PlayerPrefs.GetInt("Highscore0");// display
}
}
[System.Serializable]
public class Score{
public int score;
public string prefName; //write unique save string from inspector
}
public Score scores;
private void SaveScore(int index){
PlayerPrefs.SetInt(scores[index].prefName, scores[index].score);
}
private int GetScore(int index){
return PlayerPrefs.GetInt(scores[index].prefName, 0);
}
private void SaveAllScores(){
for(int i = 0; i < scores.Length; i++){
SaveScore(i);
}
}
private void LoadAllScores(){
for(int i = 0; i < scores.Length; i++){
scores[index].score = GetScore(i);
}
}
Edit: And instead of saving everything every frame, you should save it only when you score has changed - added.