# FontSize

**URL:** https://discussions.unity.com/t/fontsize/533234
**Category:** Scripting
**Tags:** Scripting
**Created:** [March 28, 2014, 1:34am UTC](https://discussions.unity.com/t/fontsize/533234 "2014-03-28T01:34:38Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Findo](https://avatars.discourse-cdn.com/v4/letter/f/54ee81/32.png) [@Findo](https://discussions.unity.com/u/Findo)
#### Post date: [March 28, 2014, 1:34am UTC](https://discussions.unity.com/t/fontsize/533234/1 "2014-03-28T01:34:38Z")

</div>

I have spent numerous amounts of time trying to comprehend how to do this;  
the wiki has nothing good; nor the reference; but on google, I found this

> **[Change GUI Font size and Color?](https://discussions.unity.com/questions/13944/change-gui-font-size-and-color.html)**
>
> How can I change the font and color of a GUI.Label? And other GUI objects? I'm sorry if this has bean answered before, but all I found were questions about how to change the GameObject GUIText.

Yet still, I was confused,  
this is what I have so far.

> [@](#):
>
> using UnityEngine;  
> using System.Collections;
> 
> public class Playergui : MonoBehaviour { // cannot be named GUI or it messed with script.  
> public static bool Loser;  
> public int num = 500;  
> public Font fonts;  
> // Use this for initialization  
> void Start () {  
> Loser = true;  
> fonts = num;  
> }  
> // Update is called once per frame  
> void Update () {
> 
> }  
> void OnGUI () {  
> GUIStyle Style = new GUIStyle();  
> Style.font = fonts;  
> if (Loser == true) { // if Loser is set false, it will remove. // If assigned true again, it will reappear.  
> GUI.Box (new Rect (0, 0, 700, 700), “YOU LOSE!”,Style); // makes a GUI  
> Loser = false;  
> Loser = true;  
> }  
> // I’m pretty sure this is not the right way how to hold a gui variable  
> if (GUI.Button(new Rect(5, 1, 90, 133),“Play Game”)){  
> Debug.Log(“Clicked”);  
> }  
> }  
> }

---

<div class="post-metadata">

### Author: ![TheRaider](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/theraider/32/268520_2.png) [@TheRaider](https://discussions.unity.com/u/TheRaider)
#### Post date: [March 28, 2014, 10:40am UTC](https://discussions.unity.com/t/fontsize/533234/2 "2014-03-28T10:40:47Z")

</div>

font is the font that is uses

try Style.fontSize

---

<div class="post-metadata">

### Author: ![Graham-Dunnett](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/graham-dunnett/32/44143_2.png) [@Graham-Dunnett](https://discussions.unity.com/u/Graham-Dunnett)
#### Post date: [March 28, 2014, 11:42am UTC](https://discussions.unity.com/t/fontsize/533234/3 "2014-03-28T11:42:20Z")

</div>

Create a new unity project. Make a c# script called fontsize.cs and paste the following code in:

```auto
// c# example
using UnityEngine;
using System.Collections;

public class fontsize : MonoBehaviour {

	void OnGUI() {
		GUIStyle g = GUI.skin.GetStyle("label");
		g.fontSize = (int)(20.0f + 10.0f * Mathf.Sin(Time.time));
		GUI.Label(new Rect(10, 10, 200, 80), "Hello World!");
	}
}

```

As you probably know, the GUI system uses collections of styles grouped into skins. What this code does is simply grab the out-of-the-box style for the label component, and animate it’s font size. When you run the code you’ll note that the font doesn’t smoothly change size because their are not an infinite number of font sizes. This relies on the default (Arial) font being loaded and marked as dynamic. You cannot change the size of any font that’s not marked as dynamic.

---

<div class="post-metadata">

### Author: ![Findo](https://avatars.discourse-cdn.com/v4/letter/f/54ee81/32.png) [@Findo](https://discussions.unity.com/u/Findo)
#### Post date: [March 28, 2014, 6:47pm UTC](https://discussions.unity.com/t/fontsize/533234/4 "2014-03-28T18:47:48Z")

</div>

So… um… can you explain line 9?  
I’ve never used Mathf ☹

---

<div class="post-metadata">

### Author: ![Graham-Dunnett](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/graham-dunnett/32/44143_2.png) [@Graham-Dunnett](https://discussions.unity.com/u/Graham-Dunnett)
#### Post date: [March 28, 2014, 9:20pm UTC](https://discussions.unity.com/t/fontsize/533234/5 "2014-03-28T21:20:52Z")

</div>

> [@Findo](#):
>
> I’ve never used Mathf ☹

- Mathf is the library of maths functions in Unity.
- One of those functions is the Sin function, which, given an angle, returns the sin of that angle, which, if you recall your math lessons at school, is a number between plus and minus one.
- Rather than use an angle, I am just passing in the time in seconds. But the sin function doesn’t know that. It just gives a a repeating number every 6 seconds or so.
- Because fonts have sizes in the range, say, 12pt to 32pt, I’m starting off with 20, and then adding +/-10 to that. So I end up with a number between 10 and 30, which I use to scale the font.
