Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by JayFitz91 · Sep 21, 2014 at 10:29 AM · playerprefskeyhighscore

One highscore player pref setting highscores for all levels

Hi everyone, I seem to be having an awful lot of trouble with player prefs the last few days. I have similar code to this in each of my levels for when the level ends:

playerScript in my first level

if(healthSlider.value

     if (PlayerPrefs.GetInt("forestRushHighScore", GUICounters.highestScore) < GUICounters.score)
     {
         GUICounters.highestScore = GUICounters.score;
         PlayerPrefs.SetInt("forestRushHighScore", GUICounters.highestScore);
     }
 }

I have 8 levels, each one has a different key corresponding to that levels highscore. I also have a button on my main menu that I want to display the high scores for each level. The problem is, if I play one level, beat the high score and then check my highscores from the main menu, each level has the same high score as the level I just beat. I don't know why, I'm using each unique key.

my High Score script attached to the camera

void Update () { forestRush.text = "" + PlayerPrefs.GetInt("forestRushHighScore", GUICounters.highestScore); catchEm.text = "" + PlayerPrefs.GetInt("catchEmHighScore", GUICounters.highestScore); colorCoded.text = "" + PlayerPrefs.GetInt("colorCodedHighScore", GUICounters.highestScore); defence.text = "" + PlayerPrefs.GetInt("defenceHighScore", GUICounters.highestScore); target.text = "" + PlayerPrefs.GetInt("targetHighScore", GUICounters.highestScore); flight.text = "" + PlayerPrefs.GetInt("flightHighScore", GUICounters.highestScore); maze.text = "" + PlayerPrefs.GetInt("mazeHighScore", GUICounters.highestScore); jumpRunner.text = "" + PlayerPrefs.GetInt("jumpRunnerHighScore", GUICounters.highestScore); }

If anyone could point out something I'm doing wrong, i'd appreciate it, it's the final thing I have to do before I'm finished my game.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by JayFitz91 · Sep 21, 2014 at 12:15 PM

I think I found the issue, in my high score script, I use the unique key but with the same GUICounters.highscore varible so I don't know if maybe somewhere, its getting overwritten. Anyway I gave each level an individual high score key and now it seems to work fine. The new code:

playerScript in my first level

 if(healthSlider.value <= 0)
         {
 
             if (PlayerPrefs.GetInt("forestRushHighScore", GUICounters.forestRushHighScore) < GUICounters.score)
             {
                 GUICounters.forestRushHighScore = GUICounters.score;
                 PlayerPrefs.SetInt("forestRushHighScore", GUICounters.forestRushHighScore);
                 PlayerPrefs.SetInt("forestRushScore", GUICounters.score);
             }
             
 
             GUICounters.ammo = 50;
             GUICounters.score = 0;
             Application.LoadLevel("endGame");
 
         }

my High Score script attached to the camera

 void Update () 
     {
         forestRush.text = "" + PlayerPrefs.GetInt("forestRushHighScore", GUICounters.forestRushHighScore);
         catchEm.text = "" + PlayerPrefs.GetInt("catchEmHighScore", GUICounters.catchEmHighScore);
         colorCoded.text = "" + PlayerPrefs.GetInt("colorCodedHighScore", GUICounters.colorCodedHighScore);
         defence.text = "" + PlayerPrefs.GetInt("defenceHighScore", GUICounters.defenceHighScore);
         target.text = "" + PlayerPrefs.GetInt("targetHighScore", GUICounters.targetHighScore);
         flight.text = "" + PlayerPrefs.GetInt("flightHighScore", GUICounters.flightHighScore);
         maze.text = "" + PlayerPrefs.GetInt("mazeHighScore", GUICounters.mazeHighScore);
         jumpRunner.text = "" + PlayerPrefs.GetInt("jumpRunnerHighScore", GUICounters.jumpRunnerHighScore);
     }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

25 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

PlayerPrefs save after quit? 2 Answers

PlayerPrefs Highscore problem 1 Answer

How do I get my endless runner high score,How do I make high score for an endless runner 1 Answer

PlayerPrefs highscore system? 1 Answer

Implementing HighScore board 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges