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 Inan-Evin · Jun 12, 2012 at 04:16 PM · guitextresolutionlabel

GUI.Label question about Resolution

Hello everyone, I simply want to place texts on the screen so I use GUI.Label like this:

 GUI.Label (Rect(Screen.width - 200,Screen.height-500,200,80),"Points : ");

I can adjust it very well according to my resolution ( 1920x1080 ) but when I run the game in 1024x768 for example, texts' places will be messed up, even some of them gets out of the screen & become invisible. Is there any way to make the text occur always on the same place of the screen without changing according to the resolution ? 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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Berenger · Jun 12, 2012 at 04:36 PM

You seems to be coding in unityscript, so put that script in a Standard Assets folder (I didn't test it) :

 using UnityEngine;
 
 [System.Serializable]
 public class ViewportRect
 {
     private float m_fX = 0f, m_fY = 0f, m_fWidth = 1f, m_fHeight = 1f;
     public float x{         get{ return m_fX; }         set{ m_fX = Mathf.Clamp01(value); } }
     public float y{         get{ return m_fY; }         set{ m_fY = Mathf.Clamp01(value); } }
     public float width{     get{ return m_fWidth; }     set{ m_fWidth = Mathf.Clamp01(value); } }
     public float height{     get{ return m_fHeight; }     set{ m_fHeight = Mathf.Clamp01(value); } }
 
     public ViewportRect():this(0f,0f,1f,1f){}
     public ViewportRect( Rect r ){ FromRect(r); }
     public ViewportRect( float _x, float _y, float_width, float _height )
     {
         x = _x;
         y = _y;
         width = _width;
         height = _height;
     }
     
     public Rect ToRect()
     {
         return new Rect( x * Screen.width, y * Screen.height, width * Screen.width, height * Screen.height );
     }
     
     public ViewportRect FromRect( Rect r )
     {
         x         = r.x / Screen.width;
         y         = r.y / Screen.height;
         width     = r.width / Screen.width;
         height     = r.height / Screen.height;
         
         return this;
     }
 }

The point is to manipulate coordinate between 0 and 1. Be carefull, the ratio will be lost.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Changing a GUILabel text SIZE 3 Answers

How to input a current resolution on GuiText? 1 Answer

GUI Label Size and Position Changes With Resolution 2 Answers

Relate font size to screen size in GUISkin 2 Answers

Color.white not so much white... 3 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