- Home /
How can i make a local high score system with C#?
EDIT:
Hi, how can i make a local high score system? I want this to work so it saves my score IF it's higher than my last high score. How can i do that?
Answer by hans_vesthardt98 · Jun 19, 2013 at 06:42 PM
Hey guys, i made a local high score system myself based on my players z position. Hope this will help you if you want the same:
void Update () {
if ( transform.position.z > PlayerPrefs.GetInt ("highScore") ){
PlayerPrefs.SetInt ("highScore", Mathf.RoundToInt (transform.position.z ) );
}
}
And then here is the GUI.Box which shows me my current score (my z position) and my highest score.
void OnGUI() {
GUI.Box ( new Rect ( Screen.width-150, 0, 150, 50 ),"Score: " + Mathf.RoundToInt (transform.position.z) + "\n High Score: " + PlayerPrefs.GetInt("highScore") );
}
If you have any questions about the system, please, just ask!
Cheers
Answer by rhbrr5hrfgdfgw · Jun 15, 2013 at 05:03 PM
I didn't understand your question, do you want it to show your score? thats it? if so add a new variable called score or something var score : int = 0; and then call the score variable here GUI.Box ( new Rect ( Screen.width-150, 0, 150, 50 ),"Score: "+score); thats it?
No my question is how i can make a local high score system so on the top line of my box i have my score, that's working, and on the bottum line it says: High Score: xxx. So i want something that saves my score and shows my highest score ever in my GUI.Box
Answer by Pyrotechnic · Feb 07, 2017 at 08:43 AM
set it up so when you die or finish a round the score is compared to the highscore, then if it is higher set a variable called highscore equal to the score. Then save it using playerPerfs or dontdestroy on load. If you need exact scripts just ask.
Your answer
Follow this Question
Related Questions
Score display not working 1 Answer
Make a custom score counter in unity with c# 1 Answer
Displaying score on screen in specific place 1 Answer
Trying to get this coin system to work to no avail 1 Answer
Adding score when enemy dies (Errors) 2 Answers