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 PuneetK · Oct 08, 2013 at 02:01 PM · guiresolutionscalingaspect ratio

Is this the correct way to scale my GUI?

I'm looking to make my game multi platform, and work on multiple resolutions/aspect ratios. For the GUI, I'm using onGUI.

Initially, I had made every element follow this pattern

 Position.x = screen.width * something
 position.y = screen.height * something
 width = screen.width * something
 height = screen.height * something

But I found that it wasnt scaling very well with different resolutions, and was also ruining the images texture quality.

So then I found a different way to do it.

 Position.x = screen.width * something
 position.y = screen.height * something
 width = constant (say, 60)
 height = constant (say, 60)

This seems to work fine for different resolutions, in the editor. But I am concerned whether this method is foolproof, and if it the correct way to go about things? Please let me know if this is correct or no. And if not, let me also know the BEST way to resize/scale/reposition GUI elements for multi resolutions

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 fafase · Oct 09, 2013 at 01:37 PM 0
Share

In our previous project, we figured out that this approach is valid as long as the different devices have a ratio pretty similar.

But in the end, we had to use some macros to have proper layout.

Fact is, a phone (appro 16:10 I think) and a tab (approx 5:4 I think) have total different ratio and what looks ok on the iPad will look compressed on the phone.

So this is ok as long as ratio remains pretty equivalent.

avatar image PuneetK · Oct 09, 2013 at 05:02 PM 0
Share

Please let me know more about the "macros" you are referring to. Because I have to go for something like say 1:1 as well as 9:16 as well.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by MFen · Oct 08, 2013 at 02:14 PM

I personally like to use xRatio and yRatio like so

 xRatio = screen.width / 960;  //960 is default screen size 
 yRatio = screen.heigth / 600; //600 is default screen size
 
 Rect guiRect = new Rect (0,0, 200 * xRatio, 200 * yRatio);
Comment
Add comment · Show 6 · 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 PuneetK · Oct 08, 2013 at 02:32 PM 0
Share

So what exactly is this bit of code doing? What I mean is, how is it scaling my stuff perfectly?

avatar image MFen · Oct 08, 2013 at 03:16 PM 0
Share

This method sets up your GUI so that it will always maintain the correct shape and will resize depending on size of the screen.

avatar image PuneetK · Oct 08, 2013 at 07:54 PM 0
Share

So lets say I set it to 1280/720 does that mean that my game will always work according to 1280/720 coordinates?

avatar image PuneetK · Oct 08, 2013 at 08:08 PM 0
Share

I tried this out, and it's not working as expected. I used 60 xRatio, 60 yRatio, using 720 and 1280 as my native coordinates. Now, the resolution set by me in the editor was 1280 x 720 And the GUI is scaling to about 50% of its desired size. When I'm printing out Screen.width, I'm getting 335. But I should be getting 720, no?

avatar image PuneetK · Oct 09, 2013 at 09:43 AM 0
Share

Still waiting for an answer.

If it helps, I'm using an orthographc camera

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

Resolution & aspect ratio GUI 1 Answer

Huge Texture Not Keeping Resolution 1 Answer

UI not scaling correctly with screen resolution 1 Answer

Scaling GUI correctly according to game window resolution? 1 Answer

GUI Texture Control Problem !!!!! 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