变量分配问题

时间:2014-12-29 13:49:23

标签: variables unityscript

美好的一天每个人,我正在编写一个脚本并且它工作得非常好,但是只有这一个错误,我无法弄清楚。我在俯瞰什么?我将在下面发布错误和代码。

这是错误:

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;
}

1 个答案:

答案 0 :(得分:0)

并非我真的认为您的脚本是简单的JavaScript,但可能是您将对象Score与小写版本score

混淆