【发布时间】:2016-09-07 13:10:02
【问题描述】:
我正在编写游戏,我希望文本显示玩家分数,分数会随着时间的推移而增加。但是,它不起作用。为什么它不起作用?
#pragma strict
import UnityEngine.UI;
var score = 0;
var highScore : int;
var text : Text;
function Start() {
highScore = PlayerPrefs.GetInt("High Score");
text = GetComponent(Text);
text.text = score.ToString();
}
function Update() {
score += Time.deltaTime;
if (score >= highScore) {
highScore = score;
PlayerPrefs.SetInt("High Score", highScore);
}
text.text = score.ToString();
}
我不断收到错误:
NullReferenceException:对象引用未设置为对象的实例 Timer and Scoreboard.Update () (在 Assets/Scripts/Timer and Scoreboard.js:17)
【问题讨论】:
标签: javascript string text unity3d unityscript