我已完成UI Canvas
,然后附上UI Text
,将其命名为ScoreText
。
我还有ScoreManager
脚本用于重置乐谱并将文字写入其中。
代码
public class ScoreManager : MonoBehaviour {
public static int score;
Text text;
void Awake () {
text = GetComponent <Text> ();
score = 0;
}
void Update () {
text.text = "Score: " + score;
Debug.Log (score);
}
}
代码已附加到ScoreText
。它正在官方统一的生存射击教程中工作,也为我的项目工作。
但问题是 Text text
无法识别。
&#34;无法找到类型或命名空间 Text
。&#34;
它在unity4
中有效。我目前的项目位于unity5
。
计数在debug.log
中正常工作。现在我想设置得分文本。
答案 0 :(得分:2)
添加
using UnityEngine.UI;
在代码顶部以导入命名空间。
旁注,Unity游戏引擎的标记是Unity3d
,而不是Unity
:)