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 Wyris · Sep 06, 2013 at 01:48 PM · androidguimobilescaling

GUI scaling on mobile

Hello. I'm using a standard Unity GUI. I am trying to scale it to make my game playable on devices with different resolution. The problem is I can not figure out how to scale GUI properly according to the DPI of device's screen.

I tried this method https://gist.github.com/darktable/2018687 but for some reason it doesn't work for me on my mobile phone but on PC it does work (but if I change the resolution at runtime it stops working).

I am attaching two screenshots. The first one is from my mobile phone and the second is from my PC!

alt textalt text

screenshot_2013-09-06-19-31-55.png (9.3 kB)
scr2.png (4.0 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

Answer by perchik · Sep 06, 2013 at 01:56 PM

What I've always done is to use relative sizes in my GUI. Instead of saying this box is 50px wide, I say this box is 1.2% of Screen.Width or something similar. That way, when the screen size changes, the box changes too. Although, this is quite a painful way to do things..I usually start with my GUI laid out exactly the way I want it, absolutely, then go through and convert it to relative (by dividing the absolute numbers by the current Screen.Width)

Perhaps you could use Screen.dpi to get a better result though.

Comment
Add comment · Show 7 · 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 Wyris · Sep 06, 2013 at 02:09 PM 0
Share

Thank you for your reply. However, if I use this method, I will have to scale the GUI's fontSize. Is it possible at runtime?

avatar image perchik · Sep 06, 2013 at 02:18 PM 0
Share

Yep...let me dig up the code real quick

avatar image perchik · Sep 06, 2013 at 02:22 PM 0
Share

I think you have to change the font size for each element, ie GUI.skin.label.fontSize = 18 , GUI.skin.box.fontSize = 10` etc.

If I remember correctly, the trick with scaling font size is that you have to use $$anonymous$$athf.RoundToInt to round any floating point numbers to an integer, since fontSize takes an integer.

A better approach would be to create a second GUI Skin for mobile, and then switch out the whole skin when you're on a mobile device (with all your new font sizes written in the GUISkin)

I kinda hoped someone would post a better answer because relative size GUI's are nasty.

avatar image perchik · Sep 06, 2013 at 02:22 PM 0
Share

You know,

Another option is to use GUILayout ins$$anonymous$$d of GUI. Then you don't have to worry about fixed sizes, but you would still need a different font size for mobile

avatar image Wyris · Sep 06, 2013 at 02:30 PM 0
Share

Could you please provide a little example of how to use the GUILayout correctly to solve my problem with scaling?

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

16 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

Related Questions

size of GUI pics too big 1 Answer

Why this simple code doesnt work? 0 Answers

GUI how to make the scrollbar bigger? 1 Answer

How should I go about proper GUIText scaling for mobile devices? 0 Answers

Scaling the GUI matrix in mobile causes buttons to be off 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