【发布时间】:2018-09-11 15:14:38
【问题描述】:
我编写了一些 PlayerPref 代码来在屏幕上显示我的高分。当我第一次进入播放模式时它工作正常。但是当我第二次进入游戏模式时,高分不再有“Best:”前缀,而是显示为一个数字,直到我获得新的高分,然后“Best:”前缀又回来了.这是我的代码:
void Start ()
{
highScore.text = PlayerPrefs.GetInt("HighScore", 0).ToString();
}
if (collision.tag == "Score")
{
scoreText.text = (++score).ToString();
Destroy(collision.gameObject);
if(score > PlayerPrefs.GetInt("HighScore", 0))
{
PlayerPrefs.SetInt("HighScore", score);
highScore.text = "Best: " + score.ToString();
}
【问题讨论】: