- Home /
How do I make a custom font for a GUI button? C#
I don't want a link to reference because it usually doesn't help and I don't want to be told to use a gui.skin or something.
Thanks
Answer by numberkruncher · May 18, 2013 at 12:12 AM
You would need to provide your own GUIStyle
object and then set its font `GUIStyle.font`. You can then draw your button as follows:
public Font yourFont;
GUIStyle customButtonStyle;
void OnGUI() {
if (customButtonStyle == null) {
customButtonStyle = new GUIStyle(GUI.skin.button);
customButtonStyle.font = yourFont;
}
if (GUILayout.Button("My Button", customButtonStyle)) {
// XYZ...
}
}
Place a font asset within your project and then expose a public field public Font yourFont;
. For information on creating a font refer to: http://docs.unity3d.com/Documentation/Components/class-Font.html, then make the association using the inspector.
If you have lots of custom GUIStyle's then you can better manage them by defining a GUISkin. A GUISkin is essentially just a selection of styles.
This doesn't work, how do I name the font?
Font blackout = "Blackout_Two_A$$anonymous$$.ttf";
You need to import the font asset into your project and then drag and drop the asset into the "Your Font" property of your $$anonymous$$onoBehaviour.
Your answer
Follow this Question
Related Questions
My OnGUI() Won't show the Button elements :( 0 Answers
GUI Buttons not Being Displayed 1 Answer
Error on movement script. 1 Answer
Distribute terrain in zones 3 Answers
Problem with rect and touch 1 Answer