Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

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.

share|improve this answer
    
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. –  Rohit Garg Apr 11 at 15:42
add comment
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);
}
share|improve this answer
    
The original version of this post would have instanciated a new Style every GUI tick, I've fixed that. –  Lohoris Apr 11 at 15:34
1  
Thanks. Appreciate the revision. I was too hasty in trying to help with the question. –  Jason Coombes Apr 14 at 4:21
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.