If you want to achieve unity and browser data interaction in general will be in two ways
Method One:
Application.externalcall ("SayHello", "HelloWorld");
This way you can call the JS function in the Earl puzzle in unity.
Method Two:
SendMessage ("Main Camera", "functionname", "parameters");
This way you can use the JS code in the Web page to pass parameters to unity, call the corresponding function
But I used in the process of the law idle a problem is that SendMessage only accept a parameter, which is very embarrassing, in case we reserved the function needs more than one parameter, this question puzzled me for several days
No matter how you try to pass parameters, this error will occur.
I've tried this.
SendMessage ("Main Camera", "Setwendu", 33,22);
And there's this.
SendMessage ("Main Camera", "Setwendu", "33" + "22");
But it all comes down to this mistake.
Until I saw a foreign blog one day.
Respect the copyright I pasted the original link
http://www.feedingedge.co.uk/blog/2011/03/09/browser-to-unity3d-communication-and-back-again/
I found out that unity's sendmessage was supposed to support only one parameter, no wonder I never succeeded.
A custom delimiter is used in the blog to deliver multiple parameters
In Unity:
void inboundfunction(string indata)
{
string[] Words = indata. Split (' ~ ');
Data1 = Words[0];
MOREDATA2 = words[1];
Anotherpiece3 = words[2];
}
JS in:
<script type= "Text/javascript" >
<!–
function Callbackunity (ARG)
{
Alert (ARG);
var unity = Unityobject.getobjectbyid ("Unityplayer");
Unity. SendMessage ("Rezzer", "Inboundfunction", "item1~item2~item3");
}
–>
</script>
This method combines multiple parameters into a single parameter in C # using split bar parameters to be separated so that the transfer of multiple parameters can be implemented skillfully
Unity-Released WebGL uses SendMessage to pass multiple parameters