Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by Pietie · Jun 02, 2013 at 11:11 PM · guimatrixmatrix4x4

GUI Matrix problem

Hi, is there way to scale GUI without aspect ratio deformation? Here's my matrix code:

GUI.matrix = Matrix4x4.TRS(Vector3.zero,Quaternion.identity,new Vector3(Screen.width/960f,Screen.height/640f,1f));

alt text

If I use Matrix4x4.Scale with same width as height (640), that's look fine, but can't be nothing aligned at right side of screen (with Screen.width - xxx etc.)

alt text

Can someone help me? And sorry for my bad English, I am Czech. :)

výstřižek.jpg (54.2 kB)
výstřižek2.jpg (43.7 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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by aldonaletto · Jun 02, 2013 at 11:29 PM

You always have aspect problems when the X and Y scales are different. A common solution is to calculate only the vertical scale, and assign it to the horizontal scale as well (or vice versa):

 float yScale = Screen.height/640f;
 GUI.matrix = Matrix4x4.TRS(Vector3.zero,Quaternion.identity,new Vector3(yScale, yScale, 1f));
Comment
Add comment · Show 3 · 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 Pietie · Jun 02, 2013 at 11:53 PM 0
Share

I know, but if I use this matrix, the star never be on right of screen with Rect(Screen.width - 50, 0, 50, 50), look on second screen or here... Here's evident: alt text

výstřižek.jpg (39.5 kB)
avatar image aldonaletto · Jun 03, 2013 at 02:48 AM 1
Share

The GUI coordinates are also affected by changes in the matrix, thus Screen.width should be divided by yScale in order to compensate this:

 float yScale = Screen.height/640f;
 GUI.matrix = $$anonymous$$atrix4x4.TRS(Vector3.zero,Quaternion.identity,new Vector3(yScale, yScale, 1f));
 ...
 GUI.DrawTexture(new Rect(Screen.width/yScale - 50, 0, 50, 50), starTexture);
avatar image Pietie · Jun 03, 2013 at 06:00 PM 0
Share

Awesome! :) Thank you very much!

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

15 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

Related Questions

Can't set GUI.matrix... 1 Answer

How to get the Quaternion Rotation from a Matrix4x4 2 Answers

NullReferenceException using Matrix4x4? 2 Answers

Best way to do GUI related stuff? 1 Answer

Taking the user's screen resolution before running a GUI.matrix? 0 Answers


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