*JavaScript* High Score help (Need help with player prefs)
I have to make a high score display on the game over and menu scene, Right now I have just once you die, it displays the score you had gotten from that run on the game over scene and then resets wen you go back to menu. I have no idea how to use player prefs at all. No idea how to save or retrieve date from it. Basically I need to save the scores I get and then make the one with the highest value display on a different (the gameover and menu) scenes.
Score Script(JAVA):
static var CurrentScore : int;
var InternalScore : int;
var ScoreText : GameObject;
function Update () {
InternalScore = CurrentScore;
ScoreText.GetComponent.<Text>().text = "" + InternalScore;
}
Thanks!
Don't know if this is needed, but this is how you obtain points: (java)
function DeductPoints (DamageAmount : int) {
GlobalScore.CurrentScore +=10;
}
(on a different script called ZScore1)
Answer by Jawchewa · Apr 29, 2017 at 12:08 AM
There are pretty much two functions that you will need to worry about with PlayerPrefs.
PlayerPrefs.SetInt("High Score", InternalScore);
This function will assign the value of your score to the key of "High Score".
var Score = PlayerPrefs.GetInt("High Score", 0);
This function will let you retrieve your score from playerprefs using the key that you assigned previously. You will probably want to place this in the Start function when you are loading your object. The second parameter is the default value if it doesn't already exist in PlayerPrefs.
More details about the various functions in PlayerPrefs can be found in Unity's documentation:
How do I make it so the highest valued highscore shows in a text??
Your answer
Follow this Question
Related Questions
How to save a value in player prefs? Var. (java) 0 Answers
Highscore with player prefs help. (JAVASCRIPT) 0 Answers
Player prefs confusion + high score display (Java) 0 Answers
Saving highscore for multiple scenes 1 Answer
Correct Call function On Gui ? 0 Answers