I need to set the value of a static member in unity from my browser using javascript:
In Unity3D, I have the following script file:
ScriptName: Glob.js
static var myValue;
function setValue() {
Glob.myValue=15;
}
In my browser, I’m trying to call the function setValue as follow:
//u is the unity object:
u.getUnity().SendMessage("Glob", "setValue", "");
the javascript function doesn’t give any error, but the value myValue or the function setValue is not getting called in unity, how can I change a global static member with JavaScript in order to affect unity internal values?
The first parameter to SendMessage is the name of a GameObject, so make sure you’ve set the GameObject’s name correctly, either in the Hierarchy pane or through code.
I don’t use Unity’s javascript, but you may also need to declare a string parameter to the setValue function, even if you have no data to pass - that is the required signature for message receivers.
Thank you for your quick response, I tried to add argument to the function setValue(ar:String), still not working,
what do you mean by: “make sure you’ve set the GameObject’s name correctly, either in the Hierarchy pane or through code.” ? can you give me an example please?
in Unity my file is: Glob.js and contains the code, from javascript I use: u.getUnity().SendMessage(“Glob”, “setValue”, “”); ?