I seem to run into a little snag when trying to create 3dtext.
I’ve copied a 3dtext script but its missing the Mesh Renderer part, the material to be precise.
The script so far in start() :
void Start () {
Font ArialFont = (Font)Resources.GetBuiltinResource(typeof(Font), "Arial.ttf");
GameObject myTextObject = new GameObject("test");
Vector3 tempPosition = new Vector3( 0,0,6 );
myTextObject.transform.position = tempPosition;
myTextObject.AddComponent("TextMesh");
myTextObject.AddComponent("MeshRenderer");
TextMesh textMeshComponent = myTextObject.GetComponent<TextMesh>();
MeshRenderer meshRendererComponent = myTextObject.GetComponent<MeshRenderer>();
textMeshComponent.font = ArialFont;
textMeshComponent.text = "im alive";
// i thought this part set the renderer material
myTextObject.renderer.material.shader=Shader.Find("GUI/Text Shader");
}
When i run it, i see weird blocks instead of text.
I then check out the inspector, I see under Mesh Renderer - Materials no elements have been selected.
If I select a diffrent font in the Text Mesh, the text is shown in the Game view. Further more, under Mesh Renderer - Materials there is now a font material present.
Can anyone point me in the right direction how to set the Font Material in the GameObject’s Mesh Renderer?
Many thanks.
Regards,
Ed.