• 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
0
Question by EvaXephon · Oct 31, 2013 at 07:13 PM · unityplayer

How do I make the Unity web player resize at runtime?

I'm trying to make a web game that fills the user's browser window, and updates if the user re-sizes the browser window, like t$$anonymous$$s:

http://dat.marsxplr.com/play

T$$anonymous$$s is the HTML that I'm using:

     <html xmlns="http://www.w3.org/1999/xhtml">
         <head>
             <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
             <title>Game Title</title>
             <script type='text/javascript' src='https://ssl-webplayer.unity3d.com/download_webplayer-3.x/3.0/uo/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: window.innerWidth,
                     height: window.innerHeight,
                     params: { enableDebugging:"0" }
                    
                 };
                 var u = new UnityObject2(config);
                
                 jQuery(function() {
      
                     var $missingScreen = jQuery("#unityPlayer").find(".missing");
                     var $brokenScreen = jQuery("#unityPlayer").find(".broken");
                     $missingScreen.$$anonymous$$de();
                     $brokenScreen.$$anonymous$$de();
      
                     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], "BoobieClicker.unity3d");
                 });
                
                 function GetUnity ()
                 {
                     var unity = document.getElementById("UnityObject");
                     if(unity == null) {
                     unity = document.getElementById("UnityEmbed");
                     }
                     return unity;
                 }
                
                 function resizeUnity()
                 {
                     var minW = 990;
                     var w;
                     if(document.all)
                     {
                        w = document.body.offsetWidth;
                     }
                     else
                     {
                        w = window.innerWidth;
                     }          
                                
                     if(w < minW)
                     w = minW;
                            
                     var unity = GetUnity();
                     unity.style.width = w;
                 }
      
             -->
             </script>
            
             <style type="text/css">
             <!--
             body {
                 margin: 0px;
                 padding: 0px;
             }
             div#unityPlayer {
                 cursor: default;
                 height: 100%;
                 width: 100%;
             }
             -->
             </style>
         </head>
         <body onLoad="resizeUnity()" onResize="resizeUnity()">
             <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>
         </body>
     </html>

The body tag is supposed to call resizeUnity() whenever the window is re-sized, but it doesn't seem to be working.

I've tested in Firefox and Chrome.

What am I doing wrong? :(

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
1
Best Answer

Answer by abhishekdeb · Mar 20, 2014 at 11:56 AM

You don't need to resize it every time. T$$anonymous$$s people have done awesome job. Check it here.

They are setting height of html and body element to 100% and making the height and width of the player 100% in teh config. Just go through the link and download the templates.

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 EvaXephon · Mar 20, 2014 at 07:33 PM 0
Share

Thank you! You are a gentleman, a scholar, and a livesaver!

avatar image abhishekdeb · Mar 21, 2014 at 04:08 AM 0
Share

welcome. :) glad it helped. Happy Coding.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Communication between unityplayer and activities 0 Answers

Android Activity access Unity Classes 0 Answers

Old camera view flickers for a couple of seconds when camera is changed 0 Answers

How to start the UnityPlayerActivity from a java plugin that overrides the basic Android Activity 1 Answer

kongregate unity 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