javascript - BCE0044 : expecting EOF, 发现 'import'

标签 javascript unity-game-engine error-handling

我正在使用 Unity ScoreManager 脚本的 Javascript 版本,当我最初将其导入到我的 Unity 项目中时,我收到一个错误消息

error BCE0018 the name "text" does not denote a valid type ('not found'). Did you mean 'NUnit.Framework.Internal.Test'?

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

BCE0044 expecting EOF, found import.

我做了一些研究,其他人对 }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;
}

最佳答案

导入命名空间必须在文件的最顶部完成,因此请将 import UnityEngine.UI; 移至 #pragma strict

关于javascript - BCE0044 : expecting EOF, 发现 'import',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52086180/

相关文章:

c# - 如何在Unity中从Uri.fromfile转换为FileProvider.getUriForFile?

unity-game-engine - Unity 2019.2.9f1 在 MacOS Mojave 上崩溃

java - 由: java.lang.NoClassDefFoundError: com.inn.wireless.data.Users引起

python - Python中意外的意外缩进错误

javascript - 如何在 SoundManager 2 中播放 HLS 音频流

javascript - JQuery 单击除某些 div 之外的任何地方以及动态添加的 html 的问题

c# - 如何使用 Photon 进行匹配?

C++ 回调 - 未解析的外部符号

javascript - 删除一个可观察对象是否也会删除对它的订阅?

javascript - Bootstrap 工具提示未附加到单击的按钮