I’d like to have more than one webplayer on my website - is this possible? Except from the first to load, every other webplayer shows the “Unity Web Player, Install Now!” button.
Thanks!
One way to do it is to iterate through an array of unityObjects.
To make this example work you'll need to name each webplayer:
WebPlayer1.unity3d
WebPlayer2.unity3d
WebPlayer3.unity3d
WebPlayer4.unity3d
The player is embedded by calling `unityObject.embedUnity(id, name, width, height)`, the actual function is in UnityObject.js which is imported from Unity's website before you call the function. The id is simply the id inside html where you've named them accordingly to the array.
Set the amount of webplayers in the var players and make sure you have each id set in the body (`
`).
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Unity Web Player | WebPlayer</title>
<script type="text/javascript" src="http://webplayer.unity3d.com/download_webplayer-3.x/3.0/uo/UnityObject.js"></script>
<script type="text/javascript">
<!--
var unityObjectArray = new Array();
var players = 4;
for (i=0; i<players+1; i++) {
unityObjectArray *= unityObject;*
*}*
*function GetUnity() {*
*for (i=0; i<players+1; i++) {*
_if (typeof unityObjectArray *!= "undefined") {*_
<em>_return unityObjectArray*.getObjectById("unityPlayer"+i);*_</em>
<em>_*}*_</em>
<em>_*return null;*_</em>
<em>_*}*_</em>
<em>_*}*_</em>
<em>_*for (i=0; i<players+1; i++) {*_</em>
<em><em>_if (typeof unityObjectArray *!= "undefined") {*_</em></em>
<em><em><em>_unityObjectArray*.embedUnity("unityPlayer"+i, "WebPlayer"+i+".unity3d", 200, 200);*_</em></em></em>
<em><em><em>_*}*_</em></em></em>
<em><em><em>_*}*_</em></em></em>
<em><em><em>_*-->*_</em></em></em>
<em><em><em>_*</script>*_</em></em></em>
<em><em><em>_*<style type="text/css">*_</em></em></em>
<em><em><em>_*<!--*_</em></em></em>
<em><em><em>_*body {font-family: Helvetica, Verdana, Arial, sans-serif;background-color: white;color: black;text-align: center;}*_</em></em></em>
<em><em><em>_*a:link, a:visited {color: #000;}*_</em></em></em>
<em><em><em>_*a:active, a:hover {color: #666;}*_</em></em></em>
<em><em><em>_*div.content {margin: auto;width: 400px;}*_</em></em></em>
<em><em><em>_*div.missing {margin: auto;position: relative;top: 50%;width: 193px;}*_</em></em></em>
<em><em><em>_*div.missing a {height: 63px;position: relative;top: -31px;}*_</em></em></em>
<em><em><em>_*div.missing img {border-width: 0px;}*_</em></em></em>
<em><em><em>_*div#unityPlayer1,*_</em></em></em>
<em><em><em>_*div#unityPlayer2,*_</em></em></em>
<em><em><em>_*div#unityPlayer3,*_</em></em></em>
<em><em><em>_*div#unityPlayer4 {*_</em></em></em>
<em><em><em>_*display: block; float: left; cursor: default;height: 200px;width: 200px;*_</em></em></em>
<em><em><em>_*}*_</em></em></em>
<em><em><em>_*-->*_</em></em></em>
<em><em><em>_*</style>*_</em></em></em>
<em><em><em>_*</head>*_</em></em></em>
<em><em><em>_*<body>*_</em></em></em>
<em><em><em>_*<div class="content">*_</em></em></em>
<em><em><em>_*<div id="unityPlayer1">*_</em></em></em>
<em><em><em>_*<div class="missing">*_</em></em></em>
<em><em><em>_*<a href="http://unity3d.com/webplayer/" title="Unity Web Player. Install now!">*_</em></em></em>
<em><em><em>_*<img alt="Unity Web Player. Install now!" src="http://webplayer.unity3d.com/installation/getunity.png" width="193" height="63" />*_</em></em></em>
<em><em><em>_*</a>*_</em></em></em>
<em><em><em>_*</div>*_</em></em></em>
<em><em><em>_*</div>*_</em></em></em>
<em><em><em>_*<div id="unityPlayer2"></div>*_</em></em></em>
<em><em><em>_*<div id="unityPlayer3"></div>*_</em></em></em>
<em><em><em>_*<div id="unityPlayer4"></div>*_</em></em></em>
<em><em><em>_*</div>*_</em></em></em>
<em><em><em>_*</body>*_</em></em></em>
<em><em><em>_*</html>*_</em></em></em>
<em><em><em>_*```*_</em></em></em>
<em><em><em>_*<p>The example is a webplayer which is 200x200px where the css tells each id to be placed alongside each other. If the webplayers are of different sizes then you'd have to take that into account when iterating through the array where embed occurs. That could be as simple as:</p>*_</em></em></em>
<em><em><em>_*```*_</em></em></em>
<em><em><em>_*var width = 300;*_</em></em></em>
<em><em><em>_*var height = 200;*_</em></em></em>
<em><em><em>_*for (i=0; i<players+1; i++) {*_</em></em></em>
<em><em><em><em>_if (typeof unityObjectArray *!= "undefined") {*_</em></em></em></em>
<em><em><em><em>_*switch (i) {*_</em></em></em></em>
<em><em><em><em>_*case 2:*_</em></em></em></em>
<em><em><em><em>_*width = 400;*_</em></em></em></em>
<em><em><em><em>_*height = 250;*_</em></em></em></em>
<em><em><em><em>_*break;*_</em></em></em></em>
<em><em><em><em>_*case 3:*_</em></em></em></em>
<em><em><em><em>_*width = 500;*_</em></em></em></em>
<em><em><em><em>_*height = 300;*_</em></em></em></em>
<em><em><em><em>_*break;*_</em></em></em></em>
<em><em><em><em>_*default:*_</em></em></em></em>
<em><em><em><em>_*}*_</em></em></em></em>
<em><em><em><em><em>_unityObjectArray*.embedUnity("unityPlayer"+i, "WebPlayer"+i+".unity3d", width, height);*_</em></em></em></em></em>
<em><em><em><em><em>_*}*_</em></em></em></em></em>
<em><em><em><em><em>_*}*_</em></em></em></em></em>
<em><em><em><em><em>_*```*_</em></em></em></em></em>
<em><em><em><em><em>_*<p>*_</em></em></em></em></em>
<em><em><em><em><em>_*Also have a look at <a href="http://www.41post.com/3513/programming/embedding-the-unity-web-player-with-jquery">Embedding the Unity Web Player with jQuery</a>*_</em></em></em></em></em>
<em><em><em><em><em>_*</p>*_</em></em></em></em></em>