Web Page communicating with Unity

I am trying to get my Unity web page communicate with Unity. I have this in the web page:
function SaySomethingToUnity()
{
var unity = unityObject.getObjectById(“unityPlayer”);
unity.SendMessage(“MainCamera”, “MyFunction”);
}
I activate the above code with an HTML button.

In Unity my JS file, called GUIButton, attached to the MainCamera object has this code:

function MyFunction()
{
GUI.Button(Rect(10,100,150,30),“From the Web”);
}

When I click the HTML button to activate the JS code, nothing happens. What am I doing wrong?

Thanks,
prof.t.adamson@gmail.com

2 Answers

2

Try adding an empty string to the argument call:

unity.SendMessage("MainCamera", "MyFunction", "");

In-depth reading over here.

Thanks for the suggestion. I tried it and still no success. Is it possible for me to get a more specific example? The example given on the Unity help section is a bit too abstract for me to understand. I had success in getting Unity to talk to the web page, but no success in doing it the other way around. Thanks again for your input.