Sign up Calendar Latest Topics
 
 
 


Reply
  Author   Comment  
J53 Industries

Senior Member
Registered:
Posts: 107
Reply with quote  #1 

Hello, I have been having trouble with a script that I created for a high score system. I have used these scripts before and they have worked fine however on this project they are giving me problems. The score dislpays fine with the "score" script however it does not set a high score. Both scripts are attached to empty game objects.

Here is the in game script that sets the high score-


 var scoretext : UI.Text;
  private var score : int = 0;
  
  function Awake() 
  {
  InvokeRepeating("UpdateScore" , .50, .50);
  }
      function UpdateScore() 
      {
      score += 1;
  
      scoretext.text = "Time Survived: " + score.ToString();
  }
  
      
      function GameOver()
  {
      if(score > PlayerPrefs.GetInt("TimeSurvived")) 
  {
      PlayerPrefs.SetInt("TimeSurvived", score);
          
          }
          
          Application.LoadLevel("0");
          
          }
 


Here is the second script that is supposed to dislpay the high score at the menu-


     var TimeSurvived : UI.Text;
      
      function Awake() { 
      
          TimeSurvived.text = "Longest Survival:  " + PlayerPrefs.GetInt("TimeSurvived").ToString();
          
          }
 


So if anyone has any ideas or could help me in finding out how to set a high score and display it that would be greatly appreciated thanks in advance.



__________________
Check Out My Apps Below

https://play.google.com/store/apps/developer?id=J53+Industries
0
Grumpy

Senior Member
Registered:
Posts: 318
Reply with quote  #2 
Hey from first glance I can't see a problem.

Have you put Debug.Log(PlayerPrefs.GetInt("TimeSurvived")); under PlayerPrefs.SetInt("TimeSurvived", score);? It will be easier to determine if it's a saving error or a display error then.
0
Previous Topic | Next Topic
Print
Reply

Quick Navigation:

Easily create a Forum Website with Website Toolbox.