Search Unity

How can I set the general font size of Arial(packed with Unity) font?

Discussion in 'Scripting' started by JorobusLab, Jul 24, 2014.

  1. JorobusLab

    JorobusLab

    Joined:
    Jul 3, 2014
    Posts:
    78
    Hi guys, I require some help here. Change the general font size for custom added fonts is easy, you can do that in the Inspector. But, what about the Arial font, which is the only one already packed in any game. I can't just find it in the Assets folder and set the general font size manually. How can I do that programatically? Since I want to set the font size depending on the screen height.
     
  2. herman111

    herman111

    Joined:
    May 11, 2014
    Posts:
    119
    need to use a guistye...plenty of answers on here....guifontsize just search
     
  3. JorobusLab

    JorobusLab

    Joined:
    Jul 3, 2014
    Posts:
    78
    Thanks for answer herman. I do know that posibility, but that implies many lines of code, I was wondering, if it exist a straight way to achieve it.
     
  4. herman111

    herman111

    Joined:
    May 11, 2014
    Posts:
    119
    only thing I can think of is to use the Arial from the windows Font folder...not sure where it is on a mac
     
  5. JorobusLab

    JorobusLab

    Joined:
    Jul 3, 2014
    Posts:
    78
    That's cool, but how do I set(programmatically) the default font size for that imported font?
     
  6. herman111

    herman111

    Joined:
    May 11, 2014
    Posts:
    119
    GUIText can change fontsize...if using a gui.Label or box ...script must contain a guiStyle
     
  7. herman111

    herman111

    Joined:
    May 11, 2014
    Posts:
    119
    Code (CSharp):
    1.  
    2.  
    3. public Color myColor;
    4. public int fontsize;
    5.  
    6. void OnGUI ()  {
    7. // Create Label style
    8.  
    9. GUIStyle myLabel = new GUIStyle(GUI.skin.label);
    10. myLabel.fontSize = fontsize;
    11. // Load Font
    12. Font myFont = (Font)Resources.Load("Fonts/SF Comic Script Bold", typeof(Font));
    13. myLabel.font = myFont;
    14. // color for Label
    15. myLabel.normal.textColor = myColor;
    16. // Label using Style
    17.  
    18. GUI.Label (new Rect(10,10,500,80), "SCORE:  " + score, myLabel);
    19. GUI.Label (new Rect(10,70,500,80), "HEALTH:  " + health, myLabel);
    20. GUI.Label (new Rect(10,130,500,80), "LIVES:  " + lives, myLabel);
    21. GUI.Label (new Rect(1100,10,600,80), "HIGHSCORE:  "+ highscore, myLabel);
    22. }
    Make a folder called Resources and one called Fonts inside it...store your fonts in the Fonts folder
     
    Last edited: Jul 30, 2014
  8. austin_farmer90

    austin_farmer90

    Joined:
    May 4, 2014
    Posts:
    42
    I'd definitely recommend a gui skin. They're really not that hard to implement and it will be useful for font size and tons of other stuff as well.
     
  9. JorobusLab

    JorobusLab

    Joined:
    Jul 3, 2014
    Posts:
    78
    Yes, after research the only solution is a GUISkin, changing values of fontSize of each widget, which is not pretty, about 10, 15 lines of code. Thought that was a simpler solution, one that can allow me to access to the default font size of any font. Thank you all guys for the help.