【问题标题】:How to access variable in JS script from C# script?如何从 C# 脚本访问 JS 脚本中的变量?
【发布时间】:2015-02-05 17:10:19
【问题描述】:

我在 Unity3d 上有一个游戏,我使用 JS (UnityScript) 和 C# 编写脚本。 在 JS 脚本中我有一个变量,我需要在 C# 脚本中访问它。

有可能做这样的事情吗?

Script.js:

public var myVarible;

Script.cs:

class A {
    void B() {
        Script script; // Compiler can't see Script
        script = GameObject.Find ("MyScripts").GetComponent<Script> ();
        script.myVariable = false;
    }
}

【问题讨论】:

标签: c# unity3d unityscript


【解决方案1】:

C#代码在JS代码之前编译,所以一般来说,而JS代码可以 访问 C# 类,相反是不可能的。但是,您可以 通过将脚本移动到特殊文件夹来影响编译顺序 它们是较早编译的。您可以将您的 Test01JS 脚本移动到 名为“插件”的文件夹,然后它就可以工作了。

source

also this

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-30
    • 1970-01-01
    • 2017-03-09
    相关资源
    最近更新 更多