• 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 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
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

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

Sorry, maybe the screenshots weren't much accurate. $$anonymous$$y 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
0

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
Add comment · 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 :(

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

Splitting the game view - part camera, part opaque navigational panel at runtime 1 Answer

Output second camera to second screen? 0 Answers

Keep GameObject on a corner of the screen 1 Answer

How to make your UI fit any iOS resolution? 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges