Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by ThePuppetMaster · Oct 21, 2015 at 07:14 AM · 2dscalescalingmobileoptimization

2D Mobile GUI Scaler

I've tried to find a scaler for my mobile game and I realized that I could just use the screen size and divide or multiply the width and height to get the location automatically scaled. This did work for my two GUI labels BUT, I didn't take into account that the size on different resolution screens would look either too large or to small. Is there a way that I can change the size of the text so that it always looks the same on all screens? I apologize if this is a stupid question, as I am new to Unity. This is just my text code to create it on start (I took out some other stuff that wasn't for the GUI).

 public Font myFont;
 public GUIText scoreTxt;
 public GUIText highscoreTxt;

void OnGUI(){

     GUIStyle myStyle = new GUIStyle();
     myStyle.font = myFont;
     GUI.Label(new Rect(Screen.height / 54,Screen.width / 21, 400, 200), "Score:" + score.ToString(), myStyle);
     GUI.Label(new Rect(Screen.height / 23,Screen.width * temp, 200, 200), life.ToString(), myStyle);
 }
Comment
Add comment · Show 1
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 ThePuppetMaster · Oct 21, 2015 at 09:16 AM 0
Share

I have found out that you can vary the size of the text with the font size with myStyle.fontSize = num. I still don't know how i could set up a int that would vary from screen size.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ThePuppetMaster · Oct 21, 2015 at 09:46 AM

OK, I figured out how to scale the size, and it really is just like the location.

 public Font myFont;
 public int fontsize2;

    void OnGUI(){

     fontsize = (Screen.height / fontsize2) + (Screen.width / fontsize2);

     GUIStyle myStyle = new GUIStyle();
     myStyle.font = myFont;
     myStyle.fontSize = fontsize;
     GUI.Label(new Rect(Screen.height / 54,Screen.width / 21, 400, 200), "Score:" + score.ToString(), myStyle);
     GUI.Label(new Rect(Screen.height / 23,Screen.width * temp, 200, 200), life.ToString(), myStyle);
 }

Using myStyle, which is my custom pixel font, I can declare the font size within the code with myStyle.font and have that set as a private int. I can then say that the fontsize is Screen.height and Screen.width divided by public int fontsize2. After a little messing around in the editor I set fontsize2 to around 25.

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

40 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 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

UI Mobile Scaling 1 Answer

Gradually editing the scale of an object 1 Answer

How to scale game objects according to screen size 0 Answers

Objects jump/warp for a little distance after regain the focus in Android 0 Answers

Scale/Stretch game scene to fit any device screen? Not referring to UI 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