I’ve tried the following Javascript code in the browser to communicate with the Unity file…
document.getElementById(“unityPlayer”).SendMessage(“GameObject”, “WebAsset”, “testing!!”);
GetUnity().SendMessage(“GameObject”, “WebAsset”, “testing!!”);
GetUnity().SendMessage(“WebAsset”, “testing!!”);
But I’m not getting the “testing!!” string in Unity itself. What am I doing wrong?
It’s very basic code… I execute the assetpath() function from inside Unity and that works fine. But I never get the “testing!!” string. Anyone have any ideas?
<script type="text/javascript" src="http://webplayer.unity3d.com/download_webplayer-3.x/3.0/uo/UnityObject.js"></script>
<script type="text/javascript" language="javascript">
function GetUnity() {
if (typeof unityObject != "undefined") {
return unityObject.getObjectById("unityPlayer");
}
return null;
}
if (typeof unityObject != "undefined") {
unityObject.embedUnity("unityPlayer", "WebPlayer/WebPlayer.unity3d", 760, 456);
}
function assetpath() {
alert("came to assetpath START");
document.getElementById("unityPlayer").SendMessage("GameObject", "WebAsset", "testing!!");
// GetUnity().Facebook.SendMessage("ActivateGame", "");
// alert("GetUnity():"+GetUnity());
<?php //echo 'the helloworld from php'; ?>
// GetUnity().SendMessage("GameObject", "WebAsset", "testing!!");
// GetUnity().SendMessage("WebAsset", "testing!!");
alert("came to assetpath END");
}
</script>
<p class="header"><span>Unity Web Player | </span>WebPlayer</p>
<div class="content">
<div id="unityPlayer">
<div class="missing">
<a href="http://unity3d.com/webplayer/" title="Unity Web Player. Install now!">
<img alt="Unity Web Player. Install now!" src="http://webplayer.unity3d.com/installation/getunity.png" width="193" height="63" />
</a>
</div>
</div>
</div>
<p class="footer">« created with <a href="http://unity3d.com/unity/" title="Go to unity3d.com">Unity</a> »</p>