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 Theacesofspades · Nov 05, 2012 at 03:48 AM · localhighscoretable

Highscore table

Hello everyone. I need to make a highscore table for my game but im not even sure where to begin. Can someone point me in the right direction. I do have a bit of experience with the unityscript so it wont be to much of a problem im just not to sure where to even start. Its not going to be a networking highscore table just a local one. Can someone help 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

4 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by hirenkacha · Nov 05, 2012 at 04:45 AM

This script may help I guess. Dont just copy paste it. Try to understand it, then edit as per your requirment. The script is in C# as I prefer C# for development.

 using UnityEngine;
 using System.Collections;
 
 public class HighScore: MonoBehaviour 
 {
     public bool levelComplete;
     public string highscorePos;
     public int score;
     public int temp;
     
     void Start () 
     {
         score=0;
     }
     
     void OnLevelComplete () 
     {
         levelComplete=true;
         score=10000; //values from your scoring logic
         for(int i=1; i<=5; i++) //for top 5 highscores
         {
             if(PlayerPrefs.GetInt("highscorePos"+i)<score)     //if cuurent score is in top 5
             {
                 temp=PlayerPrefs.GetInt("highscorePos"+i);     //store the old highscore in temp varible to shift it down 
                 PlayerPrefs.SetInt("highscorePos"+i,score);     //store the currentscore to highscores
                 if(i<5)                                        //do this for shifting scores down
                 {
                     int j=i+1;
                     PlayerPrefs.SetInt("highscorePos"+j,temp);    
                 }
             }
         }
     }
     
     void OnGUI() 
     {
         if(levelComplete)
         {
             for(int i=1; i<=5; i++)
             {
                 GUI.Box(new Rect(100, 75*i, 150, 50), "Pos "+i+". "+PlayerPrefs.GetInt("highscorePos"+i));
             }
         }
     }
 }
Comment
Add comment · Show 2 · 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 MaX1984 · Feb 10, 2014 at 05:00 PM 0
Share

Thanks for the script, it works almost perfect. I added score = temp; at the end, but there is still a problem. If you beat the second score it writes down the score 2 times (second and third position). Try to fix it, but i can't :(

avatar image Francheesecake MaX1984 · Jan 04, 2017 at 09:03 PM 0
Share

I had the same issue, I think I fixed it by adding a boolean that remembers if you already updated the score, so it doesn't do it more than once... Is this the issue you have?

avatar image
2

Answer by UsmanMir · Mar 09, 2014 at 12:00 PM

Instead of adding "score = temp;" at the end try

       if(i<5)       //do this for shifting scores down
       {
           int j=i+1;

           score = PlayerPrefs.GetInt("highscorePos"+j);    //Try and put this here

           PlayerPrefs.SetInt("highscorePos"+j,temp);
       }

that should chain track the scores and allow for a proper leader board.

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 Meater6 · Nov 05, 2012 at 04:44 AM

Obviously, you will have to use some sort of GUI to show it (unless its some sort of 3D thing), here's some basic guidelines for the UnityGUI (not saying that you need to use UnityGUI, GUI Textures are great too).

I would go about making a builtin array, of say, 10 integers, and these will be your highscores. Mathf has its Max function, can be used for sorting. There's also the javascript array which has a sort function, but I'm not 100% sure that it works with numbers, and not just words.

Now, saving your highscores, PlayerPrefs which should do the trick.

This was kind of a "shotgun" approach. I may have missed some vital information, as I did not spend too long on this answer, but it should give you some sort of guide or concept on how to do this.

Good Luck! I hope it helps.

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 stingman · Nov 05, 2012 at 04:44 AM

Check out NGUI. I mainly code in C# but you can also use JS with the plugin. It's an awesome GUI plugin. Saves a lot of time and has tons of features. You could easily create a low-draw-call GUI using NGUI and use their built in functions to access all the features of your high score table. As far as coding it goes, just save the high scores to PlayerPrefs. See the Unity Documentation regarding playerprefs.

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

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

Accessing local system ( File Browser ) 2 Answers

need help for Displaying Values? 0 Answers

loading information from a file 0 Answers

use world axis when using transform.rotate 0 Answers

[iTween] ShakePosition and local coordinates 5 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