- Home /
Trouble getting GUIText positioned correctly.
Hey everyone, I seem to be having trouble understanding GUIText correctly. Mainly what seems to be the problem is that if I have a GUIText positioned and scaled correctly in the game preview window it gets scaled down a lot if I hit maximize on play. I'm just not sure why it looks so differently between the two screens. A simple explanation of GUIText would be so helpful. Thanks in advance.
Answer by VioKyma · Dec 08, 2013 at 05:07 AM
Basically, the higher the resolution, the smaller the font will appear because it is drawn to size in pixels.
To get around this, you can either dynamically re-size the GUIText (Set font size to a factor of the resolution (Screen.width, Screen.height) OR you can allow the user to re-size the text to their liking (much like a website with usability options).
Note that either of these will require that the Font be a dynamic font.
Thanks, that's very informative. I'm just confused as to what factor of the screen I should get.
It depends on exactly what you're looking for, but you will probably just have to fiddle with the numbers to find your desired result. I would say something like the following:
Say your base resolution is 1024x768, you can re-size the text based upon this. So you will do something like (in C#):
int baseFontSize = 12;
guiText.fontSize = baseFontSize * (Screen.width/1024);
So if your screen width is 1280 (720p), then the font size will be 15. If you were worried about aspect ratio, you could do something more complex with the width and height properties, but hopefully this makes it a bit clearer for you.
I just found out that size ~200 in my custom font is equal to ~20 in arial and that was causing a ton of my confusion on this. Thanks so much for your help, you're awesome!
Your answer
Follow this Question
Related Questions
Problem Displaying Score on GUI text 0 Answers
Guitext hides PHP text on iphone 0 Answers
GUI: Text justification? 2 Answers
guiText.Text do not display text correctly 2 Answers
GUI Text line break Alt+Enter still does not work in Unity for Windows? 0 Answers