It is especially useful, when you start and initialize your unity web player.
First, you need to write java script in the web side like this.
document.getElementById("UnityContent").SendMessage("UnityObject", "UnityFunction", "argument");
If you have Unity Object, then it will be more simple like this
var u = new UnityObject2(config) ;
u.getUnity().SendMessage("UnityObject", "UnityFunction", "argument");
Then make an empty game object in unity editor. In this case, "UnityObject" is the name of the game object. Add a javascript to the object and write as below.
function UnityFunction(param : string)
{
var ret = param;
}
Then your Unity Web Player will have the message from the web server.
Caution :
While loading, Unity Web Player can not receive any messages. So, is is possible that the message is ignored. To prevent this, ask the web server to send message after completing loading like this.
function Start ()
{
Application.ExternalCall("GetMessage");
}
Application.ExternalCall("GetMessage");
}
GetMessage is a user defined function name. And write in your web server as below.
function GetMessage()
{
u.getUnity().SendMessage("IdObject", "PutPlayerId", "serfefer");
}
{
u.getUnity().SendMessage("IdObject", "PutPlayerId", "serfefer");
}
Then, web server will send a message after Unity Web Player is completely loaded, and no message will be lost.
No comments:
Post a Comment