PlayerPrefs不适用于HighScore

时间:2017-01-05 13:45:47

标签: javascript unity5

我无法为我的游戏保存高分。它根本不显示任何东西。我究竟做错了什么 ?任何帮助表示赞赏:)

Game-Over触发器工作,因为它引导播放器返回菜单屏幕。问题是缺少高分?我不确定我做错了什么,因为没有编译错误。

分数脚本:

var Score : TextMesh;
 private var score : int = 0;
 
 function Awake()
 
 {
     InvokeRepeating("UpdateScore", 0.05, 0.05);
 
 
 }
 //The ingame score-counter works properly
 function UpdateScore()
 
 {
     score += 1;
     Score.text = score.ToString();
 
 }

 //GameOver is getting triggered properly, but the HighScore value is missing from the menu-screen?
 function GameOver()
 {
 
     if(score > PlayerPrefs.GetInt("highScore"))
     {
         PlayerPrefs.SetInt("highScore", score);
      
 
     }
     Application.LoadLevel("menu");
}

菜单脚本:

 private var ray : Ray;
 private var rayCastHit : RaycastHit;
 
 var highScore3DText : TextMesh;

 //As mentioned above, the HighScore is not being displayed at all in the menu-screen
 function awake()
 
 {
     highScore3DText.text = PlayerPrefs.GetInt("highScore").ToString();
    
 }
 
 function Update () {
 
     if(Input.GetMouseButtonDown(0)) {
 
         ray = Camera.main.ScreenPointToRay(Input.mousePosition);
 
         if(Physics.Raycast (ray, rayCastHit)) {
 
             if (rayCastHit.transform.name == "playButton") {
 
                 Application.LoadLevel("MainGame");
             } } } }

0 个答案:

没有答案
相关问题