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
0
Question by DMCH · Jan 05, 2013 at 05:58 PM · guiscalescreen

Scaling GUI Components to Screensize

Hello,

I've been working on a GUI for a character screen (2D / PC standalone/ 16:9/ using OnGUI), with the usual collection of components (buttons, labels, boxes - all % of screen dimensions). It looks okay on the game scene in unity, but when I build it, the components scale, but the text remains the same size.

Is there some easy way to scale font size with screen dimensions? Should I start making actual graphics with the text in them? (I'm guessing these would scale). If so how should I go about calculating what size to make them?

EDIT

The following code is throwing this error: Ignoring invalid matrix assigned to GUI.Matrix. The matrix needs to be invertable. Did you scale by 0 on the Z axis?

Trying to figure out how to use GUI.Matrix, as suggested by RazorCut. Added this code into Awake on the script that has the GUI.

 void Awake()
 {
         // Get Screen Dimensions
         screenWidth = Screen.width;
         screenHeight = Screen.height;
         
         // Get 
         tScaleX = screenWidth/1366;
         tScaleY = screenHeight/768;
         
 }

And this code just after the call to OnGui()

 Vector3 tOffset = new Vector3(0.0f, 0.0f, 0.0f);
 Quaternion tRotation = Quaternion.Euler(0, 0, 0);
 Vector3 tScale = new Vector3(tScaleX, tScaleY, 1);
 
 Matrix4x4 tMatrix = Matrix4x4.TRS(tOffset, tRotation, tScale);

The GUI is keeping aspect ratio, but the font size doesn't increase with resolution. (This is how it worked before adding the matrix, I think) Also, in some smaller resolutions, a scrollview I added disappears.

Thanks for your help!

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 RazorCut · Jan 05, 2013 at 06:15 PM

If you are using GUI.matrix to alter the scale of your GUI then the text will also scale. If you aren't using GUI.matrix, then you will have to brute force it for sure.

Comment
Add comment · Show 10 · 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 DMCH · Jan 05, 2013 at 06:25 PM 0
Share

Thanks, will look into that now. If you don't $$anonymous$$d, I'll leave the question open for a bit, to see what other suggestions come up!

avatar image DMCH · Jan 05, 2013 at 06:59 PM 0
Share

Can you give me a bit more info on what else I need to get this working?

Vector3 tOffset = new Vector3(0.0f, 0.0f, 0.0f);

Quaternion tRotation = Quaternion.Euler(0, 0, 0);

Vector3 tScale = new Vector3(1.0f, 1.0f, 1.0f);

$$anonymous$$atrix4x4 t$$anonymous$$atrix = $$anonymous$$atrix4x4.TRS(tOffset, tRotation, tScale);

GUI.matrix = t$$anonymous$$atrix;

avatar image RazorCut · Jan 05, 2013 at 07:28 PM 0
Share

So assu$$anonymous$$g you only want to adjust scale, then your goal will be to supply the tScale vector with x and y values appropriate for the screen dimensions being rendered to versus the screen dimensions that the GUI is designed for. You'll also probably want to keep your aspect raio the same so that you don't get squashing and stuff. For example if you design your GUI elements to fit perfectly on a screen that is 1024x768 but it's being drawn on a screen that is 512x768 (this is fake, but an example) then you would want to set tScale.x to 0.5. Basically you could specify the values of tScale in the Awake() function, comparing some reference screen dimentions to the actual screen dimentions to get the tScale values.

avatar image DMCH · Jan 05, 2013 at 08:32 PM 0
Share

No luck so far. I've updated the question, if you'd like to take a look!

avatar image RazorCut · Jan 05, 2013 at 08:56 PM 0
Share

Are you setting the matrix to GUI.matrix in the OnGUI() method?

Show more comments

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

GUI - Scale GUIs According to Resolution 6 Answers

How to maintain high resolution custom background images for GUI elements on different screen sizes? 0 Answers

GUI adapting to screen resolution? 3 Answers

GUI and Screen Resolution 1 Answer

Scaling GUI Label not working? 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