How do I refer to a variable in a JS script from a C# script? I can get every other combination to work—C# variable from JS script, between two JS scripts, between two C# scripts. I really don’t know C#.
What do u mean?(:
i actually know what u mean -srry, i cant help i guess (: -ill give it at try :d
-isnt it just using the “Public”?
What data type is the variable in the JS script? and is that variable a static? Could we get some code sample to -see- what your trying to do…
What the? There’s an edit button for posts…
Also - http://www.google.com/search?gcx=c&sourceid=chrome&ie=UTF-8&q=unity+js+variable+in+c%23+script
Those are the same search results I found, but none answered my question.
Here’s a sample to illustrate what I’m talking about. All three scripts are attached to the same game object. The scripts Common and Main are in a Scripts folder, the script InputDelegate is in the PlugIns folder.
// JS script - Common.js
static var psv: float;
InputDelegate.clickTime += 1.0; // this works
// JS script - Main.js
Common.psv += 0.1; // this works
// C# script - InputDelegate.cs
using UnityEngine;
using System.Collections;
public class InputDelegate: MonoBehaviour {
public static float clickTime;
void Start () {
Common.psv += 0.1; // this doesn't work, The name `Common' does not exist in the current context
}
}
I need to set the variable psv in the JS script Common.js from the C# script InputDelegate.cs.
I found this in another thread:
Is that true? Does it mean I can’t access a JS variable from C#? This is an iPad app I’m talking about here, in case that’s relevant.
It’s not true. Unity - Scripting API: (section 3).
–Eric
OK. But that confuses things even more for me. Sounds like you can have a JS script that references a C# script or vice versa, but not both, since each would need to be compiled before the other. Is THIS the reason my C# script doesn’t work and my JS script does?
Yes.
–Eric