1
\$\begingroup\$

I'm trying to show the players name on the GUI with a label.

GUI.Label(new Rect(10,10, 100, 30), playerName);

Instead of use the default style I want to use a different font with larger character.

Any suggestion to achieve this?

\$\endgroup\$
2
\$\begingroup\$

Use GUI Skins. Create a new skin (go to Assets -> Create -> GUI skin), customize it accordingly (you have options for each kind of control), and link it to your script.

public class YourScript : MonoBehaviour
{
    public GUISkin Skin;
    ...

    public void OnGUI()
    {
         GUI.skin = Skin;
         GUI.Label(new Rect(10,10, 100, 30), playerName);
    }
}

More on GUI Skins in the official documentation here.

\$\endgroup\$
1
  • \$\begingroup\$ Also note that you can edit GUI skins in Play mode! You will see your changes in the game and they will be there when you exit Play mode. \$\endgroup\$
    – Rohit Garg
    Apr 11 '14 at 15:42
1
\$\begingroup\$
GUIStyle myStyle;

void Start ()
{
    myStyle = new GUIStyle();
    Font myFont = (Font)Resources.Load("Fonts/comic", typeof(Font));
    myStyle.font = myFont;
    myStyle.fontSize = 50;
}

void OnGUI ()
{
    GUI.Label(new Rect(10,10, 100, 30), playerName, myStyle);
}
\$\endgroup\$
2
  • \$\begingroup\$ The original version of this post would have instanciated a new Style every GUI tick, I've fixed that. \$\endgroup\$
    – o0'.
    Apr 11 '14 at 15:34
  • 1
    \$\begingroup\$ Thanks. Appreciate the revision. I was too hasty in trying to help with the question. \$\endgroup\$ Apr 14 '14 at 4:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .