I’m trying to create several text objects to display numbers for an animation. This is my code so far:
Font ArialFont = (Font)Resources.GetBuiltinResource(typeof(Font), "Arial.ttf");
GameObject myTextObject = new GameObject("test");
myTextObject.AddComponent("TextMesh");
myTextObject.AddComponent("MeshRenderer");
TextMesh textMeshComponent = myTextObject.GetComponent(typeof(TextMesh)) as TextMesh;
MeshRenderer meshRendererComponent = myTextObject.GetComponent(typeof(MeshRenderer)) as MeshRenderer;
textMeshComponent.font = ArialFont;
textMeshComponent.text = "im alive";
I’m able to create the text object, but the text appears as a pink block. I created 3d text using the editor to trouble the shoot. The only difference between text objects created in the script and editor is in the MeshRenderer portion of the inspector. Under the materials field, subfield Element 0 the scripted object has nothing while the object created in the editor says “Font Material”.
Can someone direct me as to how I can fix my code?