• 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
Question by maddFrogg · Apr 08, 2014 at 08:04 AM · camerascreenscreen.width

Keeping screen width and scaling screen height for different screen resolutions

Hi guys,

I need my game to have a constant screen width for every mobile device in the market. For this I need to scale the screen height in order to keep the same screen width, even though the screen ratio varies.

Here you have an example:

alt text

alt text

You see the width is the same for both resolutions and only the screen height varies.

Any idea of how I can do this?

Thanks in advance!

EDIT:

Found this: http://gamedesigntheory.blogspot.ie/2010/09/controlling-aspect-ratio-in-unity.html

Is there a way to edit it to scale height instead of adding black frames? (keeping the width)

Up!

forest-gameplay (1).png (271.2 kB)
forest-gameplay.png (246.5 kB)
Comment

People who like this

0 Show 0
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

2 Replies

  • Sort: 
avatar image

Answer by elhispano · Apr 08, 2014 at 09:10 AM

You need to change your camera orotographics size following the next formula:

 ortographicSize = constantWidth / aspectratio * 2f;
Comment

People who like this

0 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 maddFrogg · Apr 08, 2014 at 09:21 AM 0
Share

Sorry, maybe the screenshots weren't much accurate. My camera is 3D.

avatar image Klarax · Apr 08, 2014 at 09:53 AM 0
Share

try using Screen.SetResolution as seen in the documentation

     function Start()
     {
         var resolutions : Resolution[] = Screen.resolutions;
         // Print the resolutions
         for (var res in resolutions) {
             print(res.width + "x" + res.height);
         }
         // Switch to the lowest supported fullscreen resolution
         Screen.SetResolution (resolutions[0].width, resolutions[0].height, true);
     };
avatar image

Answer by Patel-Sagar · Apr 08, 2014 at 10:11 AM

try this:

     var verticalFOV : float =60;
     var forcedAspectRatio: float = 0.75;
     var manualNearClipPlane : float = 0.01;
     var manualFarClipPlane : float = 1000;
      
     function Update(){
         camera.projectionMatrix = Matrix4x4.Perspective(verticalFOV, forcedAspectRatio, manualNearClipPlane, manualFarClipPlane);
     }
Comment

People who like this

0 Show 1 · 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 maddFrogg · Apr 25, 2014 at 08:48 AM 0
Share

Doesn't work for me, sorry :(

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

26 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Detect touch in screen at different resolutions 2 Answers

How to 2D Camera follow with lag. 1 Answer

Capture a (screen shot) scene shot with alpha 3 Answers

same visible area regardless of aspect ratio 8 Answers

How I get sizeof pixels of object 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