【发布时间】:2018-09-15 00:01:51
【问题描述】:
我是 2D Unity 游戏开发的初学者,这是我的第一款游戏。在这个游戏中,我有两个场景——一个是游戏场景,另一个是游戏结束场景。当我尝试在游戏结束场景中显示高分时,它对我不起作用。这是我尝试过的代码:
public class highscore : MonoBehaviour {
public Text hscore;
private void Start() {
hscore.text = PlayerPrefs.GetInt("highscore", 0).ToString();
}
public void Update() {
if (GetComponent<Score>().score > PlayerPrefs.GetInt("highscore")) {
PlayerPrefs.SetInt("highscore", GetComponent<Score>().score);
hscore.text = GetComponent<Score>().score.ToString();
}
}
}
它将游戏冻结在场景中,没有其他东西可以解决这个问题。有谁知道问题是什么?任何帮助都会很有用。提前致谢。
【问题讨论】: