WebGL: Interacting with browser scripting

I am trying to access an external API via JavaScript from a WebGL build. I checked this page in the manual on how to access browser scripts from the index page.

The SendMesage function seem to be exactly what I am looking for

SendMessage ('MyGameObject', 'MyFunction', 'foobar');

This however did not work when I added the code to my JS file, so I checked the manual again and it stated this works the same as in the web player so I clicked the link for that


But it has this Javascript code:

<script type="text/javascript" language="javascript">
//initializing the WebPlayer 
var u = new UnityObject2();
u.initPlugin(jQuery("#unityPlayer")[0], "Example.unity3d");
function SaySomethingToUnity()
u.getUnity().SendMessage("MyObject", "MyFunction", "Hello from a web page!");

With this code I get a "UnityObject2 is undefined"error. How do I initialize for the WebGL? It looks like you need a .unity3d file which is not part of the WebGL build. How would I modify this to get it to work with WebGL? Or is there a better/other way to do this?

Any assistance would be very appreciated.

Did you find out the answer to your question; I’ve been beating my head on searching for an answer - I have your exact question. Just wonder if you stumbled across the answer. Unity - did you have an answer?

Hi @jrbourne.

Sorry but I have not as yet found the solution to this. If you come across one please post it here.