- Home /
Web player communication to Unity not working on Windows machines
For the Web Player I make calls from the html file to the unity player. It works great for computers running Mac OSX but not for Windows. Please if anyone can tell me why this is happening or if I can downgrade my version of Unity that might work as well. Thanks!
Here is the javascript in my html file I am using:
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
<script type="text/javascript">
<!--
var unityObjectUrl = "http://webplayer.unity3d.com/download_webplayer-3.x/3.0/uo/UnityObject2.js";
if (document.location.protocol == 'https:')
unityObjectUrl = unityObjectUrl.replace("http://", "https://ssl-");
document.write('<script type="text\/javascript" src="' + unityObjectUrl + '"><\/script>');
-->
</script>
<script type="text/javascript">
<!--
var config = {
width: 1100,
height: 740,
params: { enableDebugging:"0" }
};
var u = new UnityObject2(config);
jQuery(function() {
var $missingScreen = jQuery("#unityPlayer").find(".missing");
var $brokenScreen = jQuery("#unityPlayer").find(".broken");
$missingScreen.hide();
$brokenScreen.hide();
u.observeProgress(function (progress) {
switch(progress.pluginStatus) {
case "broken":
$brokenScreen.find("a").click(function (e) {
e.stopPropagation();
e.preventDefault();
u.installPlugin();
return false;
});
$brokenScreen.show();
break;
case "missing":
$missingScreen.find("a").click(function (e) {
e.stopPropagation();
e.preventDefault();
u.installPlugin();
return false;
});
$missingScreen.show();
break;
case "installed":
$missingScreen.remove();
break;
case "first":
break;
}
});
u.initPlugin(jQuery("#unityPlayer")[0], "Build1-13.unity3d");
u.getUnity().SendMessage("Startup", "SetTrainingType", "AirLeak");
});
-->
</script>
How do you make those calls? Do you use UnityObject.js
or UnityObject2.js
?
I updated my question to show the javascript I am using in the html file. I am using UnityObject2.js. Also I might have jumped the gun in assu$$anonymous$$g that it worked on Windows, I'm not positive that it was ever tested on Windows before now. Thanks
Answer by Graham-Dunnett · May 17, 2013 at 11:37 AM
http://docs.unity3d.com/Documentation/Manual/WorkingwithUnityObject.html
This says that getUnity()
returns null
if the plugin has not initialised. Since you call initPlugin
and then immediately call getUnity
I imagine that you're getting null. You might want the game to call back to the JS on the page to say it's loaded and ready to go, rather than just assume it's loaded and hit it with a SendMessage
.
Yes, that's what i do when i want to have website <--> Unity communication. Take a look at my answer on this question
That was the problem! I had to have Unity call a function in the html file that would then turn around and call a function back on the Unity. Thanks for the help!
Your answer
