How to save playerscore on a list
Im making a leaderboard from my game and i want to call the value from game controller script to Scoreboard script. i have a copied line of script on a leaderboard tutorial but i dont know how to modify it to get the score from the game. Can give and example. thank you in advance.
Here is the script in the gamecontroller that save score value
public void Endround()
{
isRoundActive = false;
dataCOntrollerT.SubmitNewplayerScore(playerScore);
endRoundScoretext.text = dataCOntrollerT.GetHIghestplayerScore().ToString();
PlayerPrefs.SetString("FINAL_SCORE", playerScore.ToString());
FinalScore = playerScore;
PlayerPrefs.SetInt("FINAL_SCORE" , playerScore); //saving score from the game
PlayerPrefs.Save();
}
Script where i want to save the scores in the scoreboard which i dont know how to modify it to get the score value.
public static void SaveScore(string name, int score)
{
List<playerScore> playerScores = new List<playerScore>();
for (int i = 0; i < highScoreManager.scoreCount; i++)
{
if (PlayerPrefs.HasKey("FINAL_SCORE" + i))
{
string[] scoreFormat = PlayerPrefs.GetString("FINAL_SCORE" + i).Split(new string[] { separator }, StringSplitOptions.RemoveEmptyEntries);
playerScores.Add(new playerScore(scoreFormat[0], int.Parse(scoreFormat[1])));
}
else
{
break;
}
}
if (playerScores.Count < 1)
{
PlayerPrefs.SetString("FINAL_SCORE", name + separator + score.ToString());
return;
}
playerScores.Add(new playerScore(name, score));
playerScores = playerScores.OrderByDescending(o => o.PlayerScore).ToList();
for (int i = 0; i <highScoreManager.scoreCount; i++)
{
if (i >= playerScores.Count) { break; }
PlayerPrefs.SetString("FINAL_SCORE" + i, playerScores[i].GetFormat());
}
}
Your answer
Follow this Question
Related Questions
I need a leaderboard 0 Answers
How to have a scoreboard system through multiple objects? 0 Answers
Leaderboard not working after releasing to play store 0 Answers
How do you make a scoreboard for a simple match three game?? 1 Answer
Score is being added up (in the background) and shows up at the end but not showing continuosly 1 Answer