【问题标题】:Variable Assignment Issues变量赋值问题
【发布时间】: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


【解决方案1】:

并不是我真的将您的脚本识别为简单的 JavaScript,但可能是您将对象 Score 与小写版本 score 混淆了

【讨论】:

    猜你喜欢
    • 2011-09-23
    • 2017-09-13
    • 2021-11-17
    • 2014-09-10
    • 1970-01-01
    • 2016-05-04
    • 1970-01-01
    • 2021-10-07
    • 1970-01-01
    相关资源
    最近更新 更多