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

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 :)

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>

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

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.

That works! Awesome, thank you!!! :slight_smile: