Unity 3D: Set the Font Size of Game Objects Text Component in Unity Using C#

7/27/2015 9:29:53 PM

Set the font size of a GameObject in Unity.

public static void Set_FontSize(Component component, int fontSize)
{
	if (component != null)
	{
		Set_FontSize(component.gameObject, fontSize);
	}
}
public static void Set_FontSize(GameObject gameObject, int fontSize)
{
	if (gameObject != null)
	{
		var textObject = gameObject.GetComponent<UnityEngine.UI.Text>();
		if (textObject != null)
		{
			textObject.fontSize = fontSize;
		}

		textObject = gameObject.GetComponentInChildren<UnityEngine.UI.Text>();
		if (textObject != null)
		{
			textObject.fontSize = fontSize;
		}
	}
}