- Home /
How do I create/load/save Highscores?
// Current scoring is using this script.
 var pennyPickup : AudioClip;
 var nicklePickup : AudioClip;
 var dimePickup : AudioClip;
 var quarterPickup : AudioClip;
 var looniePickup : AudioClip;
 var tooniePickup : AudioClip;
 var sentryKill : AudioClip;
 
 static var SCORE = 0;
 static var Timer = 0.0;
 static var Health = 100;
 
 function Update(){
 Timer += Time.deltaTime;
 }
 function OnControllerColliderHit(hit : ControllerColliderHit)
 {
     if(hit.gameObject.tag == "Penny")
     {
        Destroy(hit.gameObject);
        SCORE += 1;
 AudioSource.PlayClipAtPoint(pennyPickup, transform.position);
        }
 
     else if(hit.gameObject.tag == "Nickle")
     {
        Destroy(hit.gameObject);
        SCORE += 5;
        AudioSource.PlayClipAtPoint(nicklePickup, transform.position);
     }
     else if(hit.gameObject.tag == "Dime")
     {
        Destroy(hit.gameObject);
        SCORE += 10;
        AudioSource.PlayClipAtPoint(dimePickup, transform.position);
     }
     else if(hit.gameObject.tag == "Quarter")
     {
        Destroy(hit.gameObject);
        SCORE += 25;
        AudioSource.PlayClipAtPoint(quarterPickup, transform.position);
     }
     else if(hit.gameObject.tag == "Loonie")
     {
        Destroy(hit.gameObject);
        SCORE += 100;
        AudioSource.PlayClipAtPoint(looniePickup, transform.position);
     }
     else if(hit.gameObject.tag == "Toonie")
     {
        Destroy(hit.gameObject);
        SCORE += 200;
        AudioSource.PlayClipAtPoint(tooniePickup, transform.position);
 
     }
     else if(hit.gameObject.tag == "SentryGun")
     {
        Destroy(hit.gameObject);
        SCORE += 500;
        AudioSource.PlayClipAtPoint(sentryKill, transform.position);
 
     }
 print("Score "+ SCORE +"");
 
                 }
 
 function OnGUI () {
     GUI.Label (Rect (550, 124, 500, 250),"" + SCORE);
     GUI.Label (Rect (520, 224, 550, 450),"" + Timer.ToString("f1"));  
 //  GUI.Label (Rect (945, 24,`enter code here` 150, 50),"" + Health);
     }
               Comment
              
 
               
              Answer by azmat786n · Dec 06, 2012 at 11:49 PM
add one more function in this script.
 var highScore:int;
 //put these line in start function
 function Start() {
     highScore = PlayerPref.GetInt("score");
 }
 
 
 //call this function on game finish "submitScore(SCORE);"
 function submitScore(score:int) {
 
       PlayerPref.SetInt("score",score);
 
 }
Your answer
 
 
             Follow this Question
Related Questions
Saving GameObject to file 2 Answers
Saving world info 3 Answers
Using EditorUtility.OpenFilePanel outside editor? 1 Answer
Saving and loading scene specific data - (safe for scene renaming) 1 Answer
Trouble creating a text file 4 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                