统一

时间:2017-07-14 21:56:56

标签: c# unity3d game-engine

public class ArcadeScore : MonoBehaviour {

    public int score, cs;

    ScoreInMenu sm;

    void Start()
    {
        sm = gameObject.AddComponent<ScoreInMenu>();
        cs = sm.arc;
        score = 0;
        Debug.Log(cs);
    }

    void Update() {
        if (score > cs) {
            PlayerPrefs.SetInt("arcadeHighscore", score);
            PlayerPrefs.Save();
        }
    }
}

我有以下代码,它应该采用最新值并检查当前分数是否大于高分

public class ScoreInMenu : MonoBehaviour
{

    public Text scoreText;
    public int arc, tim;

    // Update is called once per frame
    void Start()
    {
        arc = PlayerPrefs.GetInt("arcadeHighscore");
        tim = PlayerPrefs.GetInt("timedHighscore");
        Debug.Log(arc);
        Debug.Log(tim);
        scoreText.text = "ARCADE: " + arc.ToString() + "\n" + "TIMED:    " + tim; //the place where I get the exception
    }
}

这是我用来在菜单中显示分数的脚本,但是我收到一个Nullreferenceexception,我尝试设置文本,虽然当我打印值时,它们不是空的。

0 个答案:

没有答案