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 BrimTheOne · Jun 06, 2013 at 08:25 PM · guipositionresolutionsizenewbie

GUI To change with screen resolution?

Before i ask my question, i would sincerely apologize for my bad grammar. English is not my native language:-)

My question is almost completely revealed in the Titel.

I would like to know, how i could make GUI resize and reposition according to what resolution it is played in.

I have already searched the forum, but either it was in JS or it was nothing a Newbie like me could understand.

I should also mention, that i am not an experienced Unity user, nor programmer.

My only experience is with C# and Basic Java..
so i would like if the answers wouldent be Hard-Coded, and not to complicated :-)

Thanks

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 xKroniK13x · Jun 06, 2013 at 08:49 PM

Screen.width finds the width of a screen and Screen.height finds height. So if you want something in the bottom right, something like this would suffice:

 GUI.Button (Rect (Screen.width - x, Screen.height - y, x, y), "Button")

Where x is the width, and y is the height. If you do not subtract the x and y from the width and height, it will be offscreen, since it is the edges.

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 BrimTheOne · Jun 06, 2013 at 09:11 PM 0
Share

So this is my code now, and it still doesent work, it just keeps sitting at the same spot no matter the resolution. it doesent go to the middle where i want it to be, and where i set it to be in my 16:10 aspect when i change to other aspect or try to build and run it in another resolution :/

By the way, i want it to be in the middle top of the screen. CordX is set to 700 in the inspector CordY is set to 610 in the inspector.

         public float CordX;
         public float CordY;
         public float SizeX;
         public float SizeY;
     
         public float textCordX;
         public float textCordY;
         public float textSizeX;
         public float textSizeY;
         
         public GUISkin curSkin;
         
         public string curRegion;
         public Texture2D regionName;    
     
         // Use this for initialization
         void Start () {
             curRegion = "Road to mishmosh";
         }
         
         // Update is called once per frame
         void Update () {
     
         }
         
     
         void OnGUI(){
         GUI.skin = curSkin;
         
         GUI.Label (new Rect(Screen.width - CordX, Screen.height - CordY,SizeX,SizeY), regionName);
         GUI.Label (new Rect (textCordX, textCordY,textSizeX,textSizeY), curRegion);
         GUI.skin.label.alignment = TextAnchor.$$anonymous$$iddleCenter;
             
             
         
         }
     
     
     
     }
avatar image xKroniK13x · Jun 07, 2013 at 10:56 PM 0
Share

To find the middle of the top, use Screen.width / 2... so something like this:

 var paddingTop : int; //This is the space from the top of the screen to the label, in pixels. 
 
 GUI.Label (new Rect(Screen.width/2 - CordX/2, paddingTop,SizeX,SizeY), regionName);

I believe that will work. You may have to adjust the - CordX/2, but I think it will behave correctly.

avatar image
0

Answer by screenname_taken · Jun 08, 2013 at 12:43 AM

What i did with my project was to set my layout (GUITexture or normal gui buttons) on the screen by using a 1280*800 res as my goal lets say.

Then measure the actual screen size and divide by the res in which i built the scene.

Then multiply the element's position by that ratio.

It resized and re placed everything that had that script. Tested it with various resolutions.

The code may be in JS but it should give an idea.

 private var ratio:float;
 private var screenHeight:float;
 
 function Awake () {
 
     screenHeight=Screen.height; //save screen into float.
     
     ratio=screenHeight/800; //ratio by which to multiply to resize the buttons.
     
     guiTexture.pixelInset.height*=ratio;
     guiTexture.pixelInset.width*=ratio;
     guiTexture.pixelInset.x*=ratio;
     guiTexture.pixelInset.y*=ratio;
 }
Comment
Add comment · 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

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

how to scale and position guiText in android 1 Answer

Different GUI Sizes in player and on mobile?? 1 Answer

C# Using Variables for GUI Rectangles 0 Answers

GUI messes up depending on the screen resolution 1 Answer

GUI position and size in different screen resolutions 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