• 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 kbumpious · May 06, 2015 at 12:37 PM · screensizeheightaspect-ratiowidth

Cutoff top and bottom of screen instead of sides when changing aspect ratio

I am making a game that constantly scrolls to one side. I have it set up to work with ratios from 9:16 to 3:4 (portrait only game). It works well with the 9:16 size, but when it is played with a 3:4 aspect ratio, the game is much easier because you can see what is coming sooner.

My thought is to cutoff the top and bottom of the scenes some instead of widening the scenes (default function of unity when I change screen ratio).

Is there any way to accomplish this? Preferably in the editor and not by using code. I would imagine this is possible though components but I can't figure it out.

I am open to any other suggestions of how to solve my problem of the game being easier in the different aspect ratios.

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

Answer by kbumpious · Aug 17, 2015 at 02:31 PM

 //attach this to your main camera object
 
     void Start () {
         float WORLD_WIDTH = 12f; //***Change this value based on how wide your world is***
         float aspectRatio = (float)Screen.width / (float)Screen.height;
         float cameraHeight = WORLD_WIDTH / aspectRatio;
         GetComponent<Camera>().orthographicSize = cameraHeight/2f;
     }
 
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 LilGames · Jun 22, 2017 at 05:14 PM 0
Share

If you prefer that your game view is never cropped at all, use this modification to kbumpious' answer:

 void Awake()
     {
         float worldWidthInUnits = 40f; // or whatever your world size is
         $$anonymous$$imumCameraSize = GetComponent<Camera>().orthographicSize;  // Get the starting default camera size and treat it as the $$anonymous$$imum
 
         float aspectRatio = (float)Screen.width / (float)Screen.height;
         float cameraHeight = worldWidthUnits / aspectRatio;
 
         if(cameraHeight/2f > GlobalVars.$$anonymous$$imumCameraSize){
             GetComponent<Camera>().orthographicSize = cameraHeight/2f;
         }        
     }

This script was tested for various aspect ratios, and uses a landscape mode as the initial starting point.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Object resolution 0 Answers

Standalone build with 3:2 aspect ratio 2 Answers

behavior of Screen object differs in Unity 3 1 Answer

Having an issue with setting the minimum size for a field size 0 Answers

Filling the screen doesn't... 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