Search Unity

Assign / change font from script

Discussion in 'Scripting' started by robhuhn, Feb 18, 2010.

  1. robhuhn

    robhuhn

    Joined:
    Jun 21, 2009
    Posts:
    113
    Hi,

    is it possible to assign a font from script? The font exists in my project.

    this is my code:
    Code (csharp):
    1.  
    2. GameObject tf = new GameObject();
    3. tf.transform.position = new Vector3(.5f, .5f, 0);
    4.  
    5. GUIText guiText = tf.AddComponent(typeof(GUIText)) as GUIText;
    6. /*
    7. guiText.font = ...
    8. */
    9. guiText.text = "test";
    10.  
     
  2. robhuhn

    robhuhn

    Joined:
    Jun 21, 2009
    Posts:
    113
    isnt it possible?
     
  3. AmazingInt

    AmazingInt

    Joined:
    Dec 7, 2009
    Posts:
    157
  4. robhuhn

    robhuhn

    Joined:
    Jun 21, 2009
    Posts:
    113
    thank you.

    i thought it could be all done by the script - creating style and font and so on - but now i assigned the font to a GUIStyle in the editor and use it in my script:

    Code (csharp):
    1.  
    2. ...
    3. public GUIStyle guiStyle = new GUIStyle();
    4. ...
    5. guiText.font = guiStyle.font;
    6. ...
    7.