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 Zynigma · Aug 12, 2013 at 05:59 PM · playerprefshighscore

Player prefs easy highscore?

I have read many pages on here about playerprefs, but what I'm thinking should work is not working. I want to set the highscore to 500 if there isn't a highscore in the player prefs already. The highscore will be saved as "monday1" in the prefs.

It seems so simple, but its not working. Please help.

 #pragma strict
 var highScore: int;
 
 function Awake()
 {
 if (!PlayerPrefs.HasKey("monday1"))
     {
         Debug.Log("there is no key, it is now set to 500!");
         PlayerPrefs.SetInt("monday1", 500);
     } 
 }
 function Start()
 {
     highScore = PlayerPrefs.GetInt("monday1");
     guiText.text = "High Score: " + highScore;
 }
Comment
Add comment · Show 4
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
avatar image robertbu · Aug 12, 2013 at 06:05 PM 0
Share

The code looks fine, and in a quick test it worked fine. Note it needs to be attached to a GUIText game object. What is the specific problem you are having?

avatar image Zynigma · Aug 12, 2013 at 06:47 PM 0
Share

It's not working. And it is attached to the GUITexture that says highscore +the variable. Did it say highscore 500 for you? When I run it, it says highscore: 0

it should say highscore: 500 since that variable doesn't exist in the playerprefs

avatar image robertbu · Aug 12, 2013 at 06:52 PM 0
Share

It says 'HighScore: 500'. Start with a new scene, create a GUIText object. Add your script above, and hit play (might change the key just to check everything out). Do you still have problems?

avatar image Zynigma · Aug 12, 2013 at 07:17 PM 0
Share

I will try it with a new scene in a little while, and get back to you guys. Thanks for all the help guys

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Narv · Aug 12, 2013 at 06:04 PM

Your question is a bit vague but I assume that you aren't getting the highScore value to equal 500? Did you try using PlayerPrefs.Save() to make sure it saves properly?

Comment
Add comment · Show 3 · 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
avatar image lancer · Aug 12, 2013 at 06:56 PM 0
Share

PlayerPrefs.Save(); is called automatically when the scene changes or when the application quits.

avatar image Zynigma · Aug 12, 2013 at 07:21 PM 0
Share

Correct, that's my problem. Do I need to call PlayerPrefs.Save() if im not changing the scene?

avatar image Narv · Aug 13, 2013 at 12:05 AM 0
Share

Thanks for the down vote @lancer on telling me something happens with the application quits and he isn't quitting the application....

From personal experience I know I had to do a PlayerPrefs.Save() to fix a playerprefs error in my scene.. It was a suggestion, but thanks for being useless about it.

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

16 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

Related Questions

PlayerPrefs save after quit? 2 Answers

PlayerPrefs Highscore problem 1 Answer

PlayerPrefs highscore system? 1 Answer

Implementing HighScore board 0 Answers

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


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