How do I change my font in code?

I can change my font in the inspector, but I don’t want to do that every time I make a level, etc. My levels are mostly governed by the same scripts, so I’d really like to set my font to Courier in code. I’d also like to set the text color.

So, I have

` public GUIStyle font;
float fontSize;

void  OnGUI ()
{
	fontSize = Screen.width * 0.03f;
	
	font.fontSize = (int)(fontSize);`

That all works fine. So I can manipulate the font size in code. How do I get the actual font and the color in code? I see that there’s a GUIStyle.font, but I don’t know how to change it. Then I also just don’t even see any sort of GUIStyle.color or anything like that.

Put your Fonts folder in a folder named Resources and then add this line of code in Start:

		style.font = Resources.Load<Font>("Fonts/COURIERSTD");

Also, I changed your “GUIStyle font” to “GUIStyle style” since that’s less confusing.

As for colors, you might be forgetting that “Color” is inside of something else. You can’t do “style.color,” but you can do “style.normal.color = Color.white;”