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 RyanFaeScotland · Mar 29, 2015 at 04:15 PM · sizefontlabelandriod

Why does my non-dynamic label text not resize in Android?

Hello UA,

I've tried many methods but no matter what I do I can't get my text labels to resize on my Android device (Galaxy S5). I'll describe what I'm looking to do, what I've tried so far, the results and then some of the resources I've used to help me. If anyone can explain why it isn't working or point me to other resources that may help I'd be grateful.

Objective

To get the player's score displayed in the top right hand corner of the screen. Arial font, fixed size but updates value as the score updates.

Attempts to Date

I've condensed the 4 ways I've tried programmatically to get the result I want into one script to demonstrate them. Here is the code:

 private void OnGUI()
     {    
         GUI.skin = skin;
         Rect location1 = new Rect(Screen.width - 240, 15, 200, 50);
         GUI.Label(location1, score.ToString());
 
         Rect location2 = new Rect(Screen.width - 240, 45, 200, 50);
         GUI.Label(location2, score.ToString(), skin.FindStyle("label"));
 
         Rect location3 = new Rect(Screen.width - 240, 75, 200, 50);
         GUI.Label(location3, "<size=40>" + score.ToString() + "</size>");

         var myStyle = new GUIStyle();
         myStyle.normal.textColor = GUI.skin.label.normal.textColor;
         myStyle.fontSize = 40;
         Rect location4 = new Rect(Screen.width - 240, 105, 200, 50);
         GUI.Label(location4, score.ToString(), myStyle);
     }

Some Source

However they only resize the text in the Unity game player and not when played on Android.

I started off just using the Arial font that is used as default in Unity however I have also tried importing the font from Windows and resizing it in the importer. This made no difference. I have also tried setting it to Dynamic, Unicode and ASCII default set. Still no difference. Source

I did notice I get a warning that 'Font size and style overrides are only supported for dynamic fonts.' on the 3rd method of setting the font size above.

Sources

Other than the above linked I've also checked out the manual on Android Features Not Supported and Getting Started With Android and Legacy GUI Script Guide and Legacy GUI Skin Guide (Legacy because I'm not using a canvas and believe this is an old way of doing it.)

Screenshots

Here are some shots of the different settings and one of the game (ignore Sonic, it is just a still background image).

The font import:

alt text

The GUISkin it is added to (this is reference in the code above):

alt text

The Camera Object that holds my Score Manager script which has the reference to the GUISkin:

(No more attachments allowed, it was only a script where I can drag and drop the GUISkin.)

End Result:

(No more attachments allowed, it shows a picture of Sonic with 3 labels in the top right corner all the same small size.)

All answers welcome, I'll try and retry things until I get this working and update the question as I try new things. Please comment if you need more information.

capture.png (12.3 kB)
capture2.png (23.5 kB)
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
1
Best Answer

Answer by RyanFaeScotland · Mar 30, 2015 at 09:23 AM

I deleted the font I had imported and the GUISkin I had created as I wanted to repeat each step systematically from scratch.

I started in reverse order, first commenting out all the code not related to a single way of increasing size and then uncommenting from the 4th section at the bottom up, deploying to Android each time.

Whilst doing so I noticed 2 things:

  1. If the height of the label box isn't big enough for the font size then it will be clipped.

  2. A dramatically increased font size on the Unity Game Player will not necessarily appear as dramatically increased on Android.

I found that to get a similar looking font size in Android I had to increase the font size by around 100. So where I was using 40 in the Game Player I needed to set it to 140 to see the same result on Android, at 40 it just looks like a normal sized font.

To be thorough I tried every method again, the 4 code ones, setting the font size on the default Arial font and importing the font Windows and setting that one; every method worked. I didn't change the font from dynamic when I imported it and out of interest I even tried making a variable fontSize, having it increment on each OnGui and used it in rendering in the 4th method. Sure enough it made an ever increasing font in the Game Player and on Android.

So in conclusion, there is a remote possibility I done something whilst trying to implement the increased size the first time round which caused conflicting settings to stop the changes working. This may have been fixed when I deleted the font and the GUISkin. However I think it is more likely that I simply chose a new font size that looked too similar to a regular font when used on Android and as a result of there not being a dramatic difference I assumed it wasn't working.

Hope this helps someone else out before they tear all their hair out as well.

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
avatar image
1

Answer by _joe_ · Mar 29, 2015 at 08:10 PM

I did not go through the whole question, but i have a very basic suggestion.

Why not switch to the new Unity UI?

http://unity3d.com/learn/tutorials/modules/beginner/ui

From experience, it will take you less time to convert all your project before you'll find a workaround with the old GUI system.

Best

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 RyanFaeScotland · Mar 30, 2015 at 07:22 AM 0
Share
  • Thanks joe. There are a few reasons I'm using the old system: it is the one used in the tutorials I'm followings, I only need 1 label displayed for the entire game so the old system will suffice, all the Google results I've been getting talk about the old system (could be cause of the terms I'm using).

I worked out what was wrong here and have posted it as an answer, it is just waiting on being moderate, but I'll switch to the new UI for my next project.

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

Changing Button/Label text size? 2 Answers

Changing the size of a GUI label 1 Answer

How to set the font size in GUI.Label 2 Answers

Changing a GUILabel text SIZE 3 Answers

multi line label with different font? 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