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 SeeSharp · Apr 28, 2014 at 01:37 AM · guipositionlocationscreen resolution

Is it possible to have GUI keep it's position across all resolutions?

Hi,

I just wanted to know if it's possible, and if so, how. I tried researching it some, but the closest I got was using Screen.Height and Screen.Width(or something like that).

I was thinking that maybe I could somehow create my "own" coordinate system for the GUI, by using the screen height and width(kind of create a plane and place GUI on it). What that basically means is that I would make a new button at the position * screen height / screen width.

Basically, I want some GUI's location to be persistent across all resolutions.

Would that method work? Or is it more complicated than that?

(Note: I didn't actually try using the method I was talking about.)

Thank you,

SeeSharp.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Ian-McCleary · Apr 28, 2014 at 01:45 AM

You can go by a coordinate system where the number you put in the X,Y are part of the resolution scale but this often puts the GUI of people with 1080p and higher resolution scales awkwardly in the middle of the screen. Make sure all GUI script is in a OnGUI function. Here is an example of set resolution.

GUI.Button(Rect(450,350,50,50))

Now to keep everything the same you can make GUI that subtracts pixels from the total screen height and length to make it a little more compatible across different screen resolutions. Here is an example of that.

GUI.Button(Rect(Screen.width*0.5-50,200-20,100,40)))

just make sure that whatever you put in the place of 50 is half of the number you put in 100 and same with 20 and 40.

Now im pretty sure there is no way to get you GUI exactly the same on every resolution but the second option is much closer and used more often by game makers.

I hope this helped you in some way or another and please leave me a comment if it didnt!

Comment
Add comment · Show 1 · 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 SeeSharp · Apr 28, 2014 at 01:56 AM 0
Share

Hi,

Thank you for your answer!

I currently don't have time to try it out, but I'll make sure to try it!

I have a question though: Is the method you provided more "accurate" than the one I mentioned?(a new button at the position * screen height / screen width)

Thank you,

SeeSharp.

avatar image
0

Answer by Jeff-Kesselman · Apr 28, 2014 at 01:50 AM

Yes, you can keep it in the same relative position across all resolutions.

The trick is what is called "normalized coordinates". These are coordinates that are between 0 and 1 where 0,0 is one corner of the screen and 1,1 is the opposite corner.

You can get normalized coordinates by dividing the x and y pixel positions by the current width and height.

You then multiply the normalized coordinates times the actual width and height when the game sets up.

An equivalent thing to do is this:

  1. Lay your gui out with pixel coordinates at a well known resolution.

  2. Store that resolution along with the X and Y yo hare using for each gui element's coordinates.

  3. When it comes time to draw, take the stored position coordinates, divide by the stored width and height, and multiply by the current width and height

Comment
Add comment · Show 2 · 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 SeeSharp · Apr 28, 2014 at 01:58 AM 0
Share

Hi,

Thank you for your answer! I will make sure to try it out!

Thank you,

SeeSharp.

avatar image Jeff-Kesselman · Apr 28, 2014 at 03:46 PM 0
Share

If it helps you out,please vote it up and mark it as the answer :)

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

23 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 avatar image

Related Questions

How to Position a GUI at the Top-Right of the Screen? 2 Answers

Changing an objects transform position 1 Answer

How to place a Gui Texture correctly? 1 Answer

How can I track the position of an Android Device on a small scale 0 Answers

Why is my GUI pushed over to the right? 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