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 Ibzy · Aug 03, 2014 at 11:22 PM · guiscalelabelmatrix4x4labels

GUI.Label font size scale - using GUISkin

I've read lots about using Matrix4x4 to scale GUI elements and it has been very useful. I now have a problem where I am using Camera.WorldToScreenPoint to position a label over a "sprite" game object, but the font size appears small on mobile devices.

If I use the Matrix to scale, the font size scales well, but the location is skewed as "go.pos.x" gets adjusted by the scale (I assume?).

Is there a way to target just the font size when it comes to the scale?

 void OnGUI(){
         //GUI.matrix = Matrix4x4.TRS (Vector3.zero, Quaternion.identity, new Vector3(scale.x, scale.y, 1));
         GUI.skin = skin;
         Level[] allLevels = FindObjectsOfType<Level>();
 
         foreach(Level l in allLevels){
             Vector3 pos = Camera.main.WorldToScreenPoint(l.transform.position);
 
             GUI.Label (new Rect(pos.x-10, Screen.height- pos.y-15, 50,50), l.levelNum.ToString ());
         }
     }

Current code - matrix commented to ensure the position is fine when not scaling (it is).

Any clues?

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 zharik86 · Aug 04, 2014 at 07:34 AM

If you want to do it by means of the OnGUI function, it is best of all to make in your GUISkin one more style for Label. And name this style, for example, is myLabelLevel. Further, you will need to set correctly type size for your style. Better to do all this as Awake () or Start (). I wrote an example below:

  public GUISkin skin = null; //reference for your skin

  void Start() {
   //For example, for landscape orientation size font is 30 for Screen.width=1920, than
   skin.GetStyle("myLabelLevel").fontSize = (int)(30.0f * Screen.width / 1920.0f);
  }

  void OnGUI() {
   GUI.skin = skin;
   Level[] allLevels = FindObjectsOfType<Level>();
 
   foreach(Level l in allLevels) {
    Vector3 pos = Camera.main.WorldToScreenPoint(l.transform.position);
    GUI.Label (new Rect(pos.x-10, Screen.height- pos.y-15, 50,50), l.levelNum.ToString (), "myLabelStyle"); //Use custom style
   }
  }

I hope that it will help you.

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 Ibzy · Aug 04, 2014 at 11:44 PM 0
Share

Thanks Zharik, your solution worked a charm! The use of an in-line scale adjustment also helped me resolve an issue with slight amendments to placement (left a few pixels, etc.) - so top props from me! :)

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

22 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

Related Questions

OnGUI called after LateUpdate screwing up debug text database 1 Answer

show entered amount gui/label 2 Answers

Scaling GUI Label not working? 1 Answer

Problem detecting Mouse Over Gui when scaling it with Matrix4x4 0 Answers

EditorGUI elements require minimum size of 24px? 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