- Home /
Question by
$$anonymous$$ · Sep 30, 2014 at 03:21 AM ·
fonttextmeshprogrammatically
TextMesh.font = ???
I have a TextMesh. I need it to be made entirely programmatically. If I don't change the font, it is a pink mess of unreadable blocks. I can then change my font in the editor, and it works fine. But when I try to change it programmatically, the text just vanishes. Where am I going wrong here?
GameObject dialogueContainer = new GameObject("Dialogue");
dialogueContainer.transform.parent = transform;
TextMesh dialogue = dialogueContainer.AddComponent<TextMesh>();
dialogue.transform.position = transform.position + new Vector3(0, 5, 0);
dialogue.text = "Hello World";
dialogue.font = new Font("Arial"); //this is the line that makes it vanish,
//but if I do this in the editor, it works great
Comment
Answer by LSPressWorks · Sep 30, 2014 at 05:23 AM
In the editor you will notice it also uses a material create on import called FontMaterial. Without that it will be jacked up pink mess. If you do by code, you must also assign this. The editor does that for you. I'd put whatever material its using into the resources folder as well....Just saying.