如何从 C# 脚本访问 JS 脚本中的变量?

How to access variable in JS script from C# script?

我在 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# code is compiled before JS code, so in general, while JS code can access C# classes, the opposite is not possible. However, you can affect the order of compilation by moving scripts into special folders which are compiled earlier. You could move your Test01JS script to a folder called "Plugins" then it works.

source

also this