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 diggerjohn · Mar 07, 2014 at 10:29 PM · guionguigui.buttongui.begingroup

gui content dynamic change with screen size

So I understand how to use Screen.width and Screen.height to set my group, box and buttons to scale with different screen sizes.

How would you control the button sizes so they are always proportional to the box? I cant seem to find a way to reference the box.

And as the buttons change how to dynamically adjust the font sizes of text in the buttons at the same time so the text always fits in the buttons. Any thoughts or insights? I did a lot of searching on this and maybe missed the answer. If you have seen it a link would be great. Thanks.

For example ....

 void OnGUI () {
 
     GUI.BeginGroup(new Rect(Screen.width/2 -(Screen.width*0.9f/2), Screen.height - Screen.height * .05f, Screen.width * .9f, Screen.height*.05f));
     GUI.Box(new Rect(0,0, Screen.width * .9f, Screen.height*.05f), "");
     GUI.Button(new Rect(5,5,100,40),"this is a bunch");
     GUI.EndGroup();
 
 }
Comment
Add comment · Show 2
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 ShadoX · Mar 08, 2014 at 12:10 AM 0
Share

For the font you'll probably have to reCreate it with the proper size set..

 GUIStyle myStyle = new GUIStyle();
 myStyle.font = myFont;
 GUI.Label(new Rect(10,10, 100, 30), "Hello World!", myStyle);

For the button - you would have to check the size of the box (assu$$anonymous$$g that the button is inside the box) and just change the buttons size depending on the box size.. (well actually the rectangle)..

So have a look at https://docs.unity3d.com/Documentation/ScriptReference/Rect.html and

get the Rect() size with

 var rect = Rect (0, 0, 10, 10);
 rect.width...
 rect.height...

and use that to calculate the buttons size.. so basically if you want the buttons size to be 1/2 of the rect, you'd just do...

 var rect = Rect (0, 0, 100, 100);
 GUI.Button(Rect(10,10,rect.width/2,rect.height/2),btnTexture)
avatar image diggerjohn · Mar 08, 2014 at 12:47 AM 0
Share

Gotcha ... so I would need to have a rect var for each of the buttons in my Group/Box and adjust them as needed. And then for the fonts I need a set that would cover the variations I anticipate and have them available to swap in as needed.
I will give this a try, and let you know. Thanks.

1 Reply

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

Answer by zharik86 · Mar 08, 2014 at 06:04 AM

Use GUI.matrix. As to work with it, watch my pregoing response. I hope, it will help you.

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 diggerjohn · Mar 08, 2014 at 12:49 PM 0
Share

Very cool, looks promising. I will try it out. Thank you.

avatar image diggerjohn · Mar 08, 2014 at 04:30 PM 0
Share

Nice, a quick test appears to be doing the trick. Now to add complexity. Thanks again!!!

avatar image diggerjohn · Mar 08, 2014 at 04:38 PM 0
Share

I am having the hardest time finding a discussion describing what makes this work. It appears that the Gui.matrix is a constant of the OnGUI function and simply calling it then effects everything within OnGUI. Sweet!!!! But if anyone can point me to a detailed discussion of how this is operating I would appreciate it. Thanks again!

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

22 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

Related Questions

[FIXED] Why is my GUI.Button always pressed? 0 Answers

GUI Error - Method not found: 'GUI.BeginGroup'. 1 Answer

OnGui Function help 1 Answer

GUI.Style is messing up big time 0 Answers

My OnGUI() Won't show the Button elements :( 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