我正在使用 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/