- Home /
GUIStyle and setting font's
I have a few font's imported into my project and I'm setting some text blocks with the code below. My question is how to set the GUIStyle to use one of my imported fonts? I've tried several ways and every one ultimately gives me a syntax error (i.e. I'm probably making a rookie mistake). I can set the font in the inspector just fine but I'd really like to have it in my script as I'll be using this treatment in a LOT of instances. Thanks in advance!
@script ExecuteInEditMode();
var labelText : String;
var labelStyle : GUIStyle;
function Update () {
labelText = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim";
labelStyle.fontSize = 30;
labelStyle.normal.textColor = Color.white;
labelStyle.wordWrap = true;
}
function OnGUI()
{
GUI.Label (Rect (50, 200, 400, 300), labelText, labelStyle);
}
Answer by fafase · Dec 28, 2013 at 12:53 AM
Have you tried:
var font:Font;
var labelStyle : GUIStyle;
function Start()
{
labelStyle.font = font;
}
Answer by mondoMSF · Dec 28, 2013 at 06:30 PM
Thanks for the answer - that doesn't produce any errors but it also doesn't seem to accomplish what I need. Lets say I have a font imported into the project named "H74". Is there a way, with code, to setup this GUIStyle to use that exact font? I can manually set this through the inspector but I'd prefer to do it with code (for a couple different reasons).
Your answer
Follow this Question
Related Questions
GuiStyle attachment problem 1 Answer
Error on GUIStyle.Draw 2 Answers
Customize a scripted GUI 1 Answer
EditorGUILayout for GUIStyle 0 Answers