- Home /
Adjust guiText.fontSize with Screen Resolution
Hello guys, I'm trying to adjust my guiText.fontSize with the device screen resolution. I'm adjusting all font sizes in the "Game" window with 535x892 as seen on the attached image below.
But if I build the .apk and install it on two diffenrent devices with diferent resolutions, the font sizes don't match the speech bubbles.
I'm now using a GuiText as a child of the speech bubble, and allining it with Object Label Script(http://wiki.unity3d.com/index.php?title=ObjectLabel).
Can someone help me please ? I'm struggling with this problem for a while now.
Thanks in advance, Burca
Answer by christoph_r · Jun 11, 2014 at 11:06 PM
You already figured out all the parts you'll need for the adjustments, you just need to put them together now. A simple way to do this, for example, would be to set a default screen width and font size, so the font size in the application would be:
guiText.fontSize = Mathf.RoundToInt (defaultSize * Screen.width / (defaultWidth * 1.0));
Of course that's the simplest approach, but it just might do the trick.
Work for me thank you :)
ps. defaultWidth is defaultWidth of screen that you used when you create Text
ex. if I create Text on 1280x800 then defaultWidth is 800
Answer by Nirav-Madhani · May 18, 2015 at 06:20 AM
if u are using GUI Skin
GUI .skin.label.fontSize = Mathf.RoundToInt (Size * Screen.width / (defaultWidth* 1.0));
GUI .skin.button.fontSize = Mathf.RoundToInt (Size * Screen.width / (defaultWidth * 1.0));