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 isaaclo97 · Oct 06, 2014 at 02:05 PM · errorscorehighscore

HighScore Gui Text (Error) Please Help! :)

This is my script,I want that the "number" (variable Counter) saved in an earlier scene It script looks if it is over the highscore and if it is save it and remember it as a highscore in another scene, I dont know that bad: S this is the one I use for another scene:

 var Counter : int;
  
 function Start(){
 Debug.Log(Counter);
 Counter = PlayerPrefs.GetInt("Score");
 guiText.text = "Score: "+Counter;
 }

 

and it works for me but now another scene and saved as highscore failing me that not only saves the previous runs, and I want to save the highest and if is lowest do nothing. What could I do?

 var Counter: int;
 var highscore: int;
  
  
 function Start (){
    Counter = PlayerPrefs.GetInt("Score");
    
   
 }
 function Update (){
  
 if(Counter>highscore);
 {
       highscore = Counter;
       guiText.text = "Normal Map HighScore : " +highscore.ToString();
       PlayerPrefs.SetInt("highscore",highscore);
  
  
 }
 }

 

Thanks, I wish it running!.

Comment
Add comment · Show 2
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 Andres-Fernandez · Oct 06, 2014 at 02:08 PM 0
Share

Already did it for you this time but please, next time format the code to make it readable (it's the fifth button from the left, the one that says Code Sample).

avatar image isaaclo97 · Oct 06, 2014 at 02:22 PM 0
Share

Oks, Sorry :)

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Andres-Fernandez · Oct 06, 2014 at 02:31 PM

Try using PlayerPrefs.Save after the SetInt.

Comment
Add comment · Show 11 · 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 isaaclo97 · Oct 06, 2014 at 02:42 PM 0
Share

I tried put a PlayerPrefes.Save(); but it isnt run, nothing was save, and the result that you get in the game is put in this picture, and i want that the best score, will put in this scene.

 var Counter: int;
 var highscore: int;
 
  
 function Start (){
    counter= PlayerPrefs.GetInt("Score");
 
   
 }
 function Update (){
 
 if(Counter>highscore);
 {
       highscore = Counter;
       guiText.text = "Normal $$anonymous$$ap HighScore : " +highscore.ToString();
       PlayerPrefs.SetInt("highscore",highscore);
       PlayerPrefs.Save();
 
 
 }
 }

This dont run.. :/

avatar image isaaclo97 · Oct 06, 2014 at 02:42 PM 0
Share
 var Counter: int;
 var highscore: int;
 
  
 function Start (){
    counter= PlayerPrefs.GetInt("Score");
 
   
 }
 function Update (){
 
 if(Counter>highscore);
 {
       highscore = Counter;
       guiText.text = "Normal $$anonymous$$ap HighScore : " +highscore.ToString();
       PlayerPrefs.SetInt("highscore",highscore);
       PlayerPrefs.Save();
 
 
 }
 }

I tried it, the other day and it doesnt run :/

avatar image Andres-Fernandez · Oct 06, 2014 at 02:44 PM 0
Share

The problem is that you are saving "highscore" but inside Start function you are trying to get "Score". Both the saved and the loaded value must have the same name. Line 6 should be:

 highscore = PlayerPrefs.GetInt("highscore");

avatar image isaaclo97 · Oct 06, 2014 at 02:59 PM 0
Share

But, var counter, the number that it give me is the number that i need in the other scene , and i need this number to check if is lower or higher than the HighScore, if i put this CODE

  var Counter: int;
     var highscore: int;
     
      
     function Start (){
        highscore = PlayerPrefs.GetInt("highscore");
     
       
     }
     function Update (){
     
     if(Counter>highscore);
     {
           highscore = Counter;
           guiText.text = "Normal $$anonymous$$ap HighScore : " +highscore.ToString();
           PlayerPrefs.SetInt("highscore",highscore);
           PlayerPrefs.Save();
     
     
     }
     }

when the scene change, the counter put 0, and i have other counter in the other scene...

avatar image isaaclo97 · Oct 06, 2014 at 03:09 PM 0
Share

Umm! Yes but how i can save the Counter variable to the PlayerPrefs? And put correct the line 6? I dont know certanly the best form

Show more comments
avatar image
0

Answer by Andres-Fernandez · Oct 06, 2014 at 03:06 PM

Ok, I understood it wrong. So you just need to save your Counter variable to the PlayerPrefs too (and replace back line 6, as what I suggested is wrong).

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
avatar image
0

Answer by cboxgo · Oct 09, 2014 at 07:34 AM

Are you sure that you saved the 'counter' in the previous scene?

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Sorting Error 0 Answers

Saving a value if it is larger than the current value... 3 Answers

Cannot compile .exe with specific .dll. (but with other .dlls created the same way) 0 Answers

Enter Trigger, display Text, then delete object 1 Answer

How to "Increase score with Y axis"? 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