- Home /
GUI Label Text Sizing problem
I am creating a GUI label, and sizing it relative to the screen size like this:
Vector2 scoreTitleSizeP = new Vector2 (scoreTitleSize.x * Screen.width, scoreTitleSize.y * menuBarHeight);
Vector2 scoreTitlePosP = new Vector2 (scoreTitlePos.x * Screen.width, scoreTitlePos.y * menuBarHeight);
GUI.Label(new Rect(Screen.width - scoreTitleSizeP.x, scoreTitlePosP.y, scoreTitleSizeP.x, scoreTitleSizeP.y), scoreTitleText, menuStyle);
This works perfectly and it positions and scales the label correctly on different screen sizes.
However, the text inside the label doesn't scale. I have searched intensively for the correct method of scaling the text but haven't found (or understood) how to do this.
I know in the GUISkin I can set the font size, but this is static and doesn't change depending on the screen size.
How can I scale the text content of the label the same way I scale the label itself? TIA!
Answer by YoungDeveloper · Jul 15, 2014 at 02:12 PM
Something like this should work.
private float temp;
public GUIStyle style_temp; //edit rest from inspector
private void Awake(){
temp = Screen.width/100f;
}
private void Start(){
style_temp.fontSize = temp * 2.4f
}
private void OnGUI(){
GUI.Label(new Rect(0,0,200,50), "Something", style_temp);
}
Your answer
Follow this Question
Related Questions
GUILabel to GUIText or Textmesh 0 Answers
OnGui doesn't work 2 Answers
GUI Text to GUI Label Script? 1 Answer
How to clear textures on screen? 1 Answer