So i have been looking around a lot, and I can’t find a good solution that doesn’t require payment. I’m looking for a way to set the font size to a certain size that will be the same on all devices. Ex: My current font size works well on the gs4, but on my friends gs2, it is way too big. I read something about setting the font to Unicode, but I can’t figure out how to do that. Please Help!
hmm, just an idea but maybe you can check for the screen resolution and change the font size of the gui accordingly, or change the gui.skin itself to a gui.skin with a smaller fontsize. your code would be something like this: if(screen.width < 400){ //change gui.skin or fontsize if possible}
This should work on the devices you mentioned:
private var resolutionIndex : int = 0;
private var screenRes : Resolution;
private var resChanged : boolean = true;
private var displayDPI : float;
private var mmToInch : float = 25.4;
private var fontSize : float;
var textHeight : float = 10; //the desired text height in mm
function ResolutionUpdate(){
Screen.SetResolution(screenRes.width, screenRes.height, true);
if(Screen.dpi == 0){
Debug.Log("Could not find the dpi of this display.");
displayDPI = 300;
}else{
displayDPI = Screen.dpi;
}
resChanged = true;
}
function ActualToPixel(){
return (displayDPI*textHeight)/mmToInch;
}
function Start(){
screenRes = Screen.currentResolution;
ResolutionUpdate();
}
function Update(){
ResolutionUpdate();
}
function OnGUI(){
GUI.skin.label.fontSize = ActualToPixel();
GUI.Label(Rect(0, 0, Screen.width, Screen.height), "AaBbCcDdEeFfGgHhIiJj");
GUI.skin.label.fontSize = 20;
GUI.Label(Rect(0, Screen.height-50, 200, 50), textHeight.ToString());
}
I tested this first on my laptop however my laptop doesn’t seem to supply a value for Screen.dpi so it doesn’t work there. I tested this on my Android GS3 and it looks like it works in producing a font size to equal a certain number of millimetres in height so I am hoping/assuming it will do the same for any device that it can get a Screen.dpi value from.
Scribe