I’m trying to generate a text mesh with code. All I’m getting are blocks where the letters should be. When I drag the font on to my object from the inspector a Font Material gets created with that font. Then the text works. What do I need to be doing to fix this? I can’t just AddComponent(“fontMesh”). I know I can create a prefab but I wanted to do it this way.
public GameObject gm;
public Font _font;
public Material myFontMaterial;
public GameObject myTextObject;
// Use this for initialization
void Start () {
_font = (Font) Resources.Load("Fonts/OCRASTD");
gm = new GameObject ("Hello");
gm.AddComponent("TextMesh");
gm.AddComponent("MeshRenderer");
gm.GetComponent<TextMesh>().text = "Hello";
gm.GetComponent<TextMesh>().font = _font;
gm.GetComponent<TextMesh>().fontSize = 40;
//gm.renderer.material = (Material) Resources.Load("New Material"); //I tried to and a material here and that didn't work.
}