Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by BenIV · Apr 13, 2017 at 07:54 PM · textplayerprefsscorehighscores

Help making a high score with player prefs/displaying it

I have to make a high score display on the game over and menu scene, Right now I have just once you die, it displayes the score you had gotten from that run and then it deletes it (I assume because the data of the score is not being saved antywhere). I have no idea how to use player prefs but basically, from what I gather, I need to save the scores I get and then make the one with the highest value display. I have no idea how.. :( Here is my score script please help (Java and the name is GlobalScore): static var CurrentScore : int; var InternalScore : int;

 var ScoreText : GameObject;
 
 function Update () {
     InternalScore = CurrentScore;
     ScoreText.GetComponent.<Text>().text = "" + InternalScore;
 
 }
 

Thanks!

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

Answer by LucyLuna · Apr 14, 2017 at 04:46 AM

Hope this helps: make an empty gameObject , then add the script below :

 public class ScoreManager{
  public static ScoreManager instance;
  public int highestScore;
 
  void Awake(){
   if (instance == null) {
             instance = this;
         }
         if (instance != this) {
             Destroy (gameObject);
         }
         if (PlayerPrefs.HasKey ("score")) {
             highgestScore = PlayerPrefs.GetInt ("score");
         } else {
             highgestScore = 0;
         }
         DontDestroyOnLoad (gameObject);
  }
  //it will save the score
   public void Save(){
         PlayerPrefs.SetInt ("score", highestScore);
     }
 }
 

Now , assign the highestScore when you want (i.e gameover)

 if(currentScore > ScoreManager.instance.highestScore){
   ScoreManager.instance.highestScore = currentScore;
   ScoreManager.instance.Save();
 }

Cheers. Wink

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 BenIV · Apr 15, 2017 at 04:52 PM 0
Share

I made a new c# script, named it Score$$anonymous$$anager. I made a empty gameObject on the gameover scene and attached the script. Im getting the errors: The name "Destory, gameObject, highgestScore, highgestScore (again), DontDestroyOnLoad, and gameObject (again), "does not exist in the current context". And also, I have no idea what to do with the second part of your response, ex: where to put it, etc. Thanks for replying! Please help more Lucy!

avatar image LucyLuna BenIV · Apr 17, 2017 at 02:20 AM 0
Share

Oops, I almost forgot

 //without this , everything will be incorrect
 public class Score$$anonymous$$anager : $$anonymous$$onoBehavior{
 
 }

and the second part is put where you want to end your game. For example: when your character collide with something that kills him, add the code there. Or when you exit the game ... etc. Hope that helps :)

avatar image BenIV LucyLuna · Apr 28, 2017 at 03:03 AM 0
Share

Do you have this for java? It seems to be in c#.

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

How do I access playerprefs from another script? 1 Answer

Highscore with player prefs help. (JAVASCRIPT) 0 Answers

Highscore and PlayerPrefs unity C# 1 Answer

Game over high score script 0 Answers

Highscore not working 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