Search Unity

How to change font's size?

Discussion in 'Immediate Mode GUI (IMGUI)' started by life1980, Mar 3, 2010.

  1. life1980

    life1980

    Joined:
    Feb 24, 2010
    Posts:
    5
    I have a font and want to display it in different size.How should I do?(I want codes, thank you~!)
     
  2. cerebrate

    cerebrate

    Joined:
    Jan 8, 2010
    Posts:
    261
    Text is actually not resizeable with code. The text is actually rendered by unity to a texture, and you cannot change this while running a game. About the only way to change the size of a font would be to:

    1: make multiple "fonts" that are all the different sizes that you set in the editor

    2: switch between which font is used at runtime in order to change the size
     
  3. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    cerebrate has it right. When you use a font as part of your UnityGUI elements you must specify the font size and we rasterize the font set at that size in the editor, that's not changeable at run-time. So as noted above, if you want multiple font sizes then you have to import one font asset at each size you'll want to use then look into using/applying GUIStyles to control which font size is used in each case.
     
  4. life1980

    life1980

    Joined:
    Feb 24, 2010
    Posts:
    5
    ok, I got it.
    thank you~
     
  5. bibbinator

    bibbinator

    Joined:
    Nov 20, 2009
    Posts:
    507
    I have some follow up questions on this:

    1. Why can't I change the character size of a 3D Text object at runtime? I understand the font material needs to be generated at the right size (which it is) at edit time but at runtime when I add a TextMesh to the scene it defaults to a Character Size of 1 which isn't useful or legible. Doesn't the character size just control the size of the polygons the font is rendered onto? I can see that my font is perfectly legible, but the 3D Text is too small to see the font.

    2. As per your suggestion, assuming I add the intermediate GUIStyles, how can I set this into a 3D Text?

    Thanks,
    Brett
     
  6. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    You could try increasing the size of the font on import to improve the quality as you scale up the text mesh.
    You can't apply GUIStyles to a text mesh, this is a feature of the GUI class.
     
  7. mooktown

    mooktown

    Joined:
    Feb 12, 2011
    Posts:
    5
    Text is resizeable with code (if you use a 3d text object). Then use Transform.localScale like so:

    (obj_showtimer being the pointer to my textmesh object I'm resizing)
     
    Last edited: Mar 5, 2011
  8. berg44

    berg44

    Joined:
    Apr 9, 2016
    Posts:
    3
    using the scale gives awful resolution... even when I go to the font import settings, I can't get my font to resize though
     
  9. srinathmaheshkulkarni

    srinathmaheshkulkarni

    Joined:
    Feb 9, 2019
    Posts:
    1
    you can change the size of the font in import settings and hit apply, after that reduce the scale in transform to gett better resolution.