Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/179.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 本地最高分_Android - Fatal编程技术网

Android 本地最高分

Android 本地最高分,android,Android,大家好,我是unity新手,需要帮助,下面是我当前分数和最高分数的代码,当前分数显示在gameover菜单中,但最高分数始终为0 using UnityEngine; 使用系统集合 公共类核心:单一行为{ public GameObject newRecordText; public GUIText thisScoreObj ; public GUIText thisHighScoreObj ; void Start () { int score = PlayerPrefs.GetI

大家好,我是unity新手,需要帮助,下面是我当前分数和最高分数的代码,当前分数显示在gameover菜单中,但最高分数始终为0

using UnityEngine;
使用系统集合

公共类核心:单一行为{

public GameObject newRecordText;
public GUIText thisScoreObj ;
public GUIText thisHighScoreObj ;

void Start () {
    int score = PlayerPrefs.GetInt ("currentScore");
    int highScoreOld = PlayerPrefs.GetInt ("highestScoreOld");

    newRecordText.SetActive (false);

    if (score > highScoreOld) {
        newRecordText.SetActive(true);
    }

    thisScoreObj.text = "" + score;
    thisHighScoreObj.text = "" + highScoreOld;

    AdjustFontSize ();
}

void AdjustFontSize() {
    if(Screen.height > 480 && Screen.width > 800){
        thisScoreObj.fontSize = 60;
        thisHighScoreObj.fontSize = 60;
    }

    else if(Screen.height <= 480 && Screen.width <= 800)        {
        thisScoreObj.fontSize = 40;
        thisHighScoreObj.fontSize = 40;
    }
}

}我认为你应该调用Application.LoadLevel(“GameOverMenu”);在方法的末尾。在方法完全完成之前,您正在加载一个新场景。这是修改过的-

void gameOver(int score) {
    //Debug.Log ("GAME OVER!!! Your score: " + score);
    if (score > highestScore) {
        highestScore = score;       
    }
    PlayerPrefs.SetInt ("currentScore", score);
    PlayerPrefs.SetInt ("highestScore", highestScore);
    PlayerPrefs.SetInt ("highestScoreOld", highestScoreOld);
    Application.LoadLevel("GameOverMenu");
}
希望有帮助。

我在下面修复它

void gameOver(int score) {
//Debug.Log ("GAME OVER!!! Your score: " + score);
if (PlayerPrefs.HasKey ("highestScore")) {
                highestScore = PlayerPrefs.GetInt ("highestScore");     
                highestScoreOld = highestScore;
        } else { 
    highestScore = 0;
    highestScoreOld = highestScore;
}
if (score > highestScore) {
    highestScore = score;       
}
PlayerPrefs.SetInt ("currentScore", score);
PlayerPrefs.SetInt ("highestScore", highestScore);
PlayerPrefs.SetInt ("highestScoreOld", highestScoreOld);
Application.LoadLevel("LoadLevel");
}
}

Imtiaj Ahmed,感谢您的发帖,但它不起作用,如果有人知道错误在哪里,请告诉meSorry它没有帮助。但我觉得你的密码还行。真奇怪。没有发现任何可疑的东西。谢谢你的帮助
void gameOver(int score) {
//Debug.Log ("GAME OVER!!! Your score: " + score);
if (PlayerPrefs.HasKey ("highestScore")) {
                highestScore = PlayerPrefs.GetInt ("highestScore");     
                highestScoreOld = highestScore;
        } else { 
    highestScore = 0;
    highestScoreOld = highestScore;
}
if (score > highestScore) {
    highestScore = score;       
}
PlayerPrefs.SetInt ("currentScore", score);
PlayerPrefs.SetInt ("highestScore", highestScore);
PlayerPrefs.SetInt ("highestScoreOld", highestScoreOld);
Application.LoadLevel("LoadLevel");