I’m trying to call a Unity function from the browser. (see http://unity3d.com/support/documentation/Manual/Unity%20Web%20Player%20and%20browser%20communication.html)
so I do this:
var unity = unityObject.getObjectById("UnityContent");
unity.SendMessage("Controller", "SetBottleColor", "2caffe");
but this doesn’t work because unityObject is null.
I have no idea what I’m dooing wrong,
I thought I might call this too soon, and the web player’s content isn’t loaded yet. But I’m now triggering this when I press a button on the page an it’s still the same problem.
Any help?
Edit:
here’s the entire javascript part of the html file:
<script type="text/javascript" src="http://webplayer.unity3d.com/download_webplayer-3.x/3.0/uo/UnityObject.js"></script>
<script type="text/javascript">
<!--
if (typeof unityObject != "undefined") {
unityObject.embedUnity("unityPlayer", "WebPlayer.unity3d", 600, 450, null, null, unityLoaded);
}
function unityLoaded(result)
{
if (result.success) {
var unity = result.ref;
var version = unity.GetUnityVersion("3.x.x");
alert("Unity Web Player loaded!
Id: " + result.id + "
Version: " + version);
//SentbottleColor();
}
else
{
alert(“Please install Unity Web Player!”);
}
}
function SentbottleColor()
{
alert(“SetBottleColor start”);
var unity = unityObject.getObjectById(“UnityContent”);
unity.SendMessage(“Controller”, “SetBottleColor”, “2caffe”);
alert(“SetBottleColor end”);
}
→