0

I have a game on Unity3d and I write scripts using JS (UnityScript) and C#. In the JS script I have a variable, which I need to access in the C# script.

Is it possible to do something like this?

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;
    }
}
1

1 Answer 1

6

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.