Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by Reverend-Speed · Jan 01, 2019 at 01:28 AM · aspect-ratiolocalscaleorthographic camerascreen.widthscreen.height

Why is my orthographic camera not resizing according to resolution / aspect?

I'm trying to create a quad which resizes to match the dimensions of an orthographic camera, no matter what resolution or aspect is set within Unity's Game view panel. For fixed dimensions like 960 x 600 or 1280 x 800, this seems to work fine - however, the fixed resolution of 1024 x 786 and all other aspects (5:4, 4:3, 3:2 etc) results in the camera bounds being wider than expected.

For example, setting the fixed resolution to x1024 y786 and running the code below results in the quad having the scale x1.024f, y0.768f, z1.0f, but the camera bounds appear to be (estimating by resizing a quad to fit within cam bounds) x1.24, y0.768.

x1.024f != x1.24

What on earth is going on? The function in question follows...

 private void ResizeScreenAndCamera () // Comments assume the set resolution is Standalone 1024 / 768
     {
         canvasCamera.orthographicSize   = Screen.height * 0.5f * objectScalar;
         // This is 0.384f , half of 768. This height is correct, but the camera does not get the intended width (1.024) - instead, it's x is closer to 1.24
 
         float screenAspect              = (float)Screen.width / (float)Screen.height;   // If the resolution in Unity is set to 1024 x 768, this results in 1.33333 etc.
         
         // Canvas Object is a MeshRenderer showing a Quad.
         float canvasObjectX             = (canvasCamera.orthographicSize * screenAspect) * 2;   // 0.512 * 2 = 1.024
         float canvasObjectY             = canvasCamera.orthographicSize * 2;                    // 0.384 * 2 = 0.768
 
         canvasObject.localScale         = new Vector3(canvasObjectX, canvasObjectY, canvasObject.localScale.z); // Results in desired size, height matches cam ortho height.
 
         RenderTexture displayRT         = new RenderTexture(Screen.width, Screen.height, 24);
         canvasTexture                   = displayRT;
 
         Debug.Log("Desktop Screen res: " + Screen.currentResolution);
         Debug.Log("Screen Width " + Screen.width + " / Screen Height " + Screen.height + " = Screen Aspect " + screenAspect);
     }

There are other cameras and UGUI objects in the scene, but this problem persists when they're all turned off.

Can anybody help me? Thanks in advance...!

PS: Bonus question - can anybody explain how to add a line break in Unity Answers? I've tried following the instructions, "to add a line break simply add two spaces to where you would like the new line to be and hit enter/return", but this does not seem to be working.

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

0 Replies

· Add your reply
  • Sort: 

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

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

Getting Device Screen Height and width in inches 2 Answers

Android orientation issue 1 Answer

How to resize a normal image then apply as a texture for GUI.Box()? 0 Answers

Screen.currentResolution = Null? 1 Answer

Screen.width & height not updated after screen rotation 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