Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

My High Score Won't Update

Discussion in 'Scripting' started by noel1993, Apr 22, 2015.

  1. noel1993

    noel1993

    Joined:
    Apr 22, 2015
    Posts:
    3
    I'm having problems with updating the high score in my game. It doesn't change from the first score that's saved to it. Any help would be much appreciated
     

    Attached Files:

  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    you don't do score*100 in the if statement...
     
  3. noel1993

    noel1993

    Joined:
    Apr 22, 2015
    Posts:
    3
    Yeah no I've tried that and I'm still only getting the same high score each time. I thought calling the checkScore method should mean the score and highscore are being compared every frame but it doesn't seem to work like that
     
  4. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    you aren't calling CheckScore every frame... you are only calling it once from the Death.cs update (I'm assuming the LoadLevel will reset the current level and the player y pos won't be less than 9 once more).

    Code (csharp):
    1.  
    2. if (score > highScore)
    3.  
    highScore is set as "score * 100", so at the moment that if is only going to be true when the score is 100 times the current highscore.

    you might want to consider holding all scores as their base value and only do the "*100 int" thing when displaying the value to the screen, would save a lot of redundant "*100" in the code and issues like this.
     
    noel1993 likes this.
  5. noel1993

    noel1993

    Joined:
    Apr 22, 2015
    Posts:
    3
    Great thanks, I got it going, didn't actually do much to do changes to it.
    Thanks for the help!