- Home /
Optimal solution to start loading the webplayer on a page upon user input?
Hey all,
I'd like to embed the webplayer in a webpage but not start loading the game automatically. Instead the user's action should start the loading. For example: an image is embedded in the webpage where the webplayer is going to be displayed (same location and size). It says 'click to play'. Upon clicking the image is swapped for the webplayer and the loading/game begins. Does anyone who is more versatile in html, php and/or javascript have an idea how to implement this?
Cheers - Frie
Answer by softrare · Nov 08, 2011 at 03:57 PM
That is because you did not include this line in the header:
<script type="text/javascript" src="http://webplayer.unity3d.com/download_webplayer-3.x/3.0/uo/UnityObject.js"></script>
I didn't mention it. Sorry.
Hello, i was wondering if this starts loading the game(assets) as soon as the page opens, or does it start after the swap?
It should start loading when the swapping was initiated.
Answer by softrare · Nov 08, 2011 at 01:50 PM
Try this:
<script type="text/javascript">
function GetUnity() {
if (typeof unityObject != "undefined") {
return unityObject.getObjectById("unityPlayer");
}
return null;
}
function WebplayerLoad() {
if (typeof unityObject != "undefined") {
unityObject.embedUnity("unityPlayer", "WebPlayer.unity3d", 800, 600);
}
}
</script>
<img src="/path/to/image" onclick="WebplayerLoad()" />
Report back whether it worked or not :)
Answer by softrare · Nov 08, 2011 at 02:04 PM
or if you insist on swapping remove the img-tag of my last answer and add this to the body section of the html document:
<script type="text/javascript">
function swap() {
var loader = document.getElementById('loader');
loader.innerHTML = "<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>";
WebplayerLoad();
}
</script>
<div id="loader"><img src="/path/to/image" width="100" height="100" onclick="swap()" /></div>
Answer by Frie · Nov 08, 2011 at 02:59 PM
Thanks for helping out! The swapping works, but instead of loading the application, the placeholder image is swapped for the ""unity web player - install now!" button! :S
Answer by Frie · Nov 08, 2011 at 04:03 PM
That works! Awesome, thank you!!! :)
Glad I could help :) Please mark the question as answered then.
Your answer
Follow this Question
Related Questions
How would I go about getting the results of a javascript variable to a string inside script? 3 Answers
How can I load multiple files from a hosted folder? 1 Answer
How would you tell if the webplayer got loaded from web or cache? 0 Answers
Unity Engine not updating to the latest version 1 Answer
Splash screen timer is too fast 2 Answers