简体   繁体   中英

Browser communication with Unity3d web player

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 doesnt give error, but the value myValue or the function setValue is not getting called, how can I change a global static member with JavaScript?

Many thanks.

It looks like you are not returning the value of the setValue function. I think the following code could work:

static var myValue;

function setValue() {
    Glob.myValue = 15;
    return Glob.myValue;
}

and

var myValueInUnity = u.getUnity().SendMessage("Glob", "setValue", "");
console.log(myValueInUnity);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM