- Home /
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);
}
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:
The GUISkin it is added to (this is reference in the code above):
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.
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:
If the height of the label box isn't big enough for the font size then it will be clipped.
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.
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
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
Follow this Question
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