Javascript BCE0044:应为EOF,已找到';导入&x27;

Javascript BCE0044:应为EOF,已找到';导入&x27;,javascript,unity3d,error-handling,Javascript,Unity3d,Error Handling,我使用的是Unity的ScoreManager脚本的Javascript版本,当我最初将其导入Unity项目时,有一个错误告诉我 错误BCE0018名称“text”不表示有效类型(“未找到”)。你是说“NUnit.Framework.Internal.Test”吗 有人有同样的问题,在回答中建议尝试添加import UnityEngine.UI。我试过了,它确实修复了BCE0018错误,但现在出现了一个全新的错误,我不知道如何修复它。新的错误是 BCE0044应为EOF,找到导入 我做了一些研究

我使用的是Unity的ScoreManager脚本的Javascript版本,当我最初将其导入Unity项目时,有一个错误告诉我

错误BCE0018名称“text”不表示有效类型(“未找到”)。你是说“NUnit.Framework.Internal.Test”吗

有人有同样的问题,在回答中建议尝试添加
import UnityEngine.UI。我试过了,它确实修复了BCE0018错误,但现在出现了一个全新的错误,我不知道如何修复它。新的错误是

BCE0044应为EOF,找到导入

我做了一些研究,其他人对
}
var
有类似的问题,但我还没有看到关于导入的问题。思想?这是我正在使用的完整脚本的副本

pragma strict


static var score : int; // The player's score.

private var text : Text;       // Reference to the Text component.

import UnityEngine.UI;

function Awake ()
{
    // Set up the reference.
    text = GetComponent (Text);

    // Reset the score.
    score = 0;
}

function Update ()
{
    // Set the displayed text to be the word "Score" followed by the score value.
    text.text = "Score: " + score;
}

导入名称空间必须在文件的最顶端完成,因此move
import UnityEngine.UI
after
#pragma strict

导入名称空间必须在文件的最顶端完成,因此移动
导入UnityEngine.UI
#pragma strict

之后,代码中有两个问题:

1
pragma strict
应该是
#pragma strict
。注意它前面的“#”

2。正如他在回答中所说,
导入UnityEngine.UI放置在错误的位置。这应该放在
#pragma strict
之后,并放在代码的其余部分之前

请注意,您应该停止使用Javascript/Unityscript。它已在Unity中停止使用,编译器也将很快被删除。你现在应该已经在用C了

这是您的新代码:

#pragma strict

import UnityEngine.UI;

static var score : int; // The player's score.

private var text : Text;       // Reference to the Text component.

function Awake ()
{
    // Set up the reference.
    text = GetComponent (Text);

    // Reset the score.
    score = 0;
}


function Update ()
{
    // Set the displayed text to be the word "Score" followed by the score value.
    text.text = "Score: " + score;
}

代码中有两个问题:

1
pragma strict
应该是
#pragma strict
。注意它前面的“#”

2。正如他在回答中所说,
导入UnityEngine.UI放置在错误的位置。这应该放在
#pragma strict
之后,并放在代码的其余部分之前

请注意,您应该停止使用Javascript/Unityscript。它已在Unity中停止使用,编译器也将很快被删除。你现在应该已经在用C了

这是您的新代码:

#pragma strict

import UnityEngine.UI;

static var score : int; // The player's score.

private var text : Text;       // Reference to the Text component.

function Awake ()
{
    // Set up the reference.
    text = GetComponent (Text);

    // Reset the score.
    score = 0;
}


function Update ()
{
    // Set the displayed text to be the word "Score" followed by the score value.
    text.text = "Score: " + score;
}