【发布时间】:2015-02-25 17:09:38
【问题描述】:
大家好,我正在编写一个脚本,它运行得非常好,但只有一个错误我无法弄清楚。我在俯瞰什么?我将在下面发布错误和代码。
这是错误:
UnassignedReferenceException: The variable gameOverScore of Score has not been assigned.
You probably need to assign the gameOverScore variable of the Score script in the inspector.
Score.Start () (at Assets/2dspaceshooter/Scripts/Score.js:10)
这是脚本:
#pragma strict
var gameOverScore:GUIText;
var gameGUI:GameObject;
private var score:int = 0;
private var isGameOver = false;
function Start () {
gameOverScore.guiText.enabled = false;
guiText.text = "Score: " + score.ToString();
}
function addScore () {
if(!isGameOver){
score += 10;
guiText.text = "Score: " + score.ToString();
}
}
function doGameOver () {
isGameOver = true;
gameGUI.SetActive(false);
guiText.text = null;
gameOverScore.guiText.enabled = true;
gameOverScore.guiText.text = "Score: "+score;
}
【问题讨论】:
-
这是 JavaScript 吗?你在什么环境下运行它?
-
我对 Unity 一无所知,但 this forum post 说将
gameOverScore制作成 Prefab 会有所帮助,不管那是什么......
标签: variables unityscript