Search Unity

TextMesh displaying blocks

Discussion in 'Scripting' started by twangsta, May 25, 2013.

  1. twangsta

    twangsta

    Joined:
    Mar 28, 2013
    Posts:
    17
    Hi,

    I have a standard TTF font file and the code below to manipulate text, at the moment I only see bocks instead of text in the color of the renderer.

    Any help would be much appreciated, what am I doing wrong here?

    Thanks in advance,
    Sid

    Code (csharp):
    1.         GameObject textObj = new GameObject("Text");
    2.  
    3.         textObj.AddComponent(typeof(TextMesh) );
    4.         textObj.AddComponent(typeof(MeshRenderer));
    5.  
    6.         MeshRenderer meshRen = (MeshRenderer) textObj.GetComponent(typeof(MeshRenderer));
    7.         TextMesh textMesh = (TextMesh) textObj.GetComponent(typeof(TextMesh));
    8.        
    9.         Material myMaterial = (Material) Resources.Load ("labelMaterial");
    10.         meshRen.material = myMaterial;
    11.        
    12.         Font myFont = (Font) Resources.Load("Courier New");
    13.         //myFont.material = myMaterial;
    14.         textMesh.font = myFont;
    15.        
    16.        
    17.         textMesh.text = "HELLO WORLD";
     
  2. karljj1

    karljj1

    Joined:
    Feb 17, 2011
    Posts:
    440
    It sounds like you have the wrong material. Are you using the correct ttf material and is it set to a text shader?

    K