Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by ataxk · Oct 26, 2011 at 09:40 AM · webplayermultiplewebsiteembed

Embedding multiple webplayers

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!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
5
Best Answer

Answer by save · Oct 26, 2011 at 11:21 AM

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 (<div id="unityPlayer1">).

<!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&lt;players+1; i++) {
         unityObjectArray[i] = unityObject;
     }

     function GetUnity() {
         for (i=0; i&lt;players+1; i++) {
             if (typeof unityObjectArray[i] != "undefined") {
                 return unityObjectArray[i].getObjectById("unityPlayer"+i);
             }
             return null;
         }
     }
     for (i=0; i&lt;players+1; i++) {
         if (typeof unityObjectArray[i] != "undefined") {
             unityObjectArray[i].embedUnity("unityPlayer"+i, "WebPlayer"+i+".unity3d", 200, 200);
         }
     }
     --&gt;
     &lt;/script&gt;
     &lt;style type="text/css"&gt;
     &lt;!--
     body {font-family: Helvetica, Verdana, Arial, sans-serif;background-color: white;color: black;text-align: center;}
     a:link, a:visited {color: #000;}
     a:active, a:hover {color: #666;}
     div.content {margin: auto;width: 400px;}
     div.missing {margin: auto;position: relative;top: 50%;width: 193px;}
     div.missing a {height: 63px;position: relative;top: -31px;}
     div.missing img {border-width: 0px;}

     div#unityPlayer1,
     div#unityPlayer2,
     div#unityPlayer3,
     div#unityPlayer4 {
         display: block; float: left; cursor: default;height: 200px;width: 200px;
     }
     --&gt;
     &lt;/style&gt;
 &lt;/head&gt;
 &lt;body&gt;
     &lt;div class="content"&gt;
         &lt;div id="unityPlayer1"&gt;
             &lt;div class="missing"&gt;
                 &lt;a href="http://unity3d.com/webplayer/" title="Unity Web Player. Install now!"&gt;
                     &lt;img alt="Unity Web Player. Install now!" src="http://webplayer.unity3d.com/installation/getunity.png" width="193" height="63" /&gt;
                 &lt;/a&gt;
             &lt;/div&gt;
         &lt;/div&gt;
         &lt;div id="unityPlayer2"&gt;&lt;/div&gt;
         &lt;div id="unityPlayer3"&gt;&lt;/div&gt;
         &lt;div id="unityPlayer4"&gt;&lt;/div&gt;
     &lt;/div&gt;
 &lt;/body&gt;

</html>

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:

var width = 300;
var height = 200;
for (i=0; i<players+1; i++) {
    if (typeof unityObjectArray[i] != "undefined") {
        switch (i) {
            case 2:
                width = 400;
                height = 250;
            break;
            case 3:
                width = 500;
                height = 300;
            break;
            default:
        }
        unityObjectArray[i].embedUnity("unityPlayer"+i, "WebPlayer"+i+".unity3d", width, height);
    }
}

Also have a look at Embedding the Unity Web Player with jQuery

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image save · Oct 27, 2011 at 09:21 AM 0
Share

Did it work for you? Let me know if you have troubles.

avatar image haider1515 · Jan 10, 2012 at 11:30 AM 1
Share

$$anonymous$$AN ur great:)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Multiple Unity web players embedded on the same page 1 Answer

Embedding Fonts Unity Web Player Windows 1 Answer

Textinputs not working when I implemented "Unity webGL" in VueJS Project 1 Answer

How implement my game on the website? 5 Answers

.unity3d file gets deleted automatically from FTP clients 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges