Saving last runs score, only adds the previous score to it.
Hello! I currently have an issue, with my last score not being added to the total score(it only adds when i start a new run). The idea was: When player health hits 0, the score he got this run gets added to allscore, after that score resets to 0. Then got the gameover scene, which supposed to show the allscore, but it doesnt add the latest score.(last run) Then stopped the time to prevent more obstacles from spawning, and destroyed the player.
healthDisplay.text = health.ToString();
scoreDisplay.text = score.ToString();
allscoredisplay.text = allscore.ToString();
if (health <= 0)
{
allscore += score;
score = 0;
PlayerPrefs.SetInt("currencyPref", allscore);
gameover.SetActive(true);
Time.timeScale = 0f;
Destroy(gameObject);
}
I dont really see what's causing the issue, I'd greatly appreciate some help. The allscore initially was made to use that currency to buy stuff, but currently due to this, it's not possible
Your answer
Follow this Question
Related Questions
How can I save this objects ? 0 Answers
A Little Help With Player Prefs 0 Answers
Continue from where you left with PlayerPRefs 2 Answers
PlayerPrefs saving and Loading 2 Answers
Save Data Android C# 0 Answers