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 PirateMonkey · Sep 14, 2014 at 11:59 PM · guipositionresolutionlabel

GUI Label Size and Position Changes With Resolution

Hey all,

I'm having this very frustrating problem with my HUD GUI interface. I would like to display and textured label in a portion of the screen. The problem is that the position and size get all wonky when I change the screen size/resolution.

Here is my very simple code:

 #pragma strict
 
 var missileSymbol : Texture2D;
 
 function OnGUI()
 {
 var symbolWidth : float = Screen.width / 10;
 var symbolHeight : float = Screen.width / 10;
 
 var xPos : float = Screen.width / 2;
 var yPos : float = Screen.height / 2;
 
 GUI.Label (Rect(xPos, yPos, symbolWidth, symbolHeight), missileSymbol);
 }

How can I fix this problem with code?

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 JDappsCR · Sep 15, 2014 at 09:29 AM

You need to have your vars "symbolWidth" "symbolHeight" "xPos" "yPos" in the Update function.

Example:

 #pragma strict
 
 var missileSymbol : Texture 2D;
 
 function Update()
 {
    var symbolWidth : float = Screen.width / 10;
    var symbolHeight : float = Screen.width / 10;
    var xPos : float = Screen.width / 2;
    var yPos : float = Screen.height / 2;
 }
 
 function OnGUI()
 {
    GUI.Label (Rect(xPos, yPos, symbolWidth, symbolHeight), missileSymbol);
 }
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 PirateMonkey · Sep 15, 2014 at 03:47 PM 0
Share

Thanks! That's great

avatar image
0

Answer by LSPressWorks · Sep 15, 2014 at 12:21 AM

I had the same issue with GUItexts, instead of usign height width and offsets, use the transforms scale and position.

Set the label to 1,1,1 in the scale. Set the width, height and offsets to 0 place the label, click on the game tab at the top. Just to the left of position x or y, when you click two little arrows appear that you can drag to increase and decrease to position.

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 PirateMonkey · Sep 15, 2014 at 12:42 AM 0
Share

But is there a way to do that in the code? $$anonymous$$aybe I don't know enough about GUIs yet, but that would involve creating the interface as a GameObject > GUITexture as opposed to doing it with OnGUI in code. Also, I'm making this game as pixel art and I'd like to avoid changing the scale where possible since I need all the pixels to be the same size.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

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

GUI To change with screen resolution? 2 Answers

GUI messes up depending on the screen resolution 1 Answer

How do I position a GUI Label over an object? 1 Answer

GUI.Label question about Resolution 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