- Home /
Multiple issues with the TextMesh component
Hi all
I'm making TextMeshes for some of my objects by duplicating the GameObject and adding a TextMesh component. This is my method:
private void __buildTextDuplicate()
{
this.__textDuplicate = Instantiate(this.gameObject,
this.gameObject.transform.position,
this.gameObject.transform.rotation) as GameObject;
this.__textDuplicate.transform.parent = this.gameObject.transform;
this.__textDuplicate.name = "Text";
// Remove our components
Destroy(this.__textDuplicate.GetComponent<Element>());
Destroy(this.__textDuplicate.GetComponent<MeshCollider>());
// Set the text material
Material textMaterial = ResourceManager.getResource<Material>("Materials", "text");
this.__textDuplicate.GetComponent<MeshRenderer>().material = textMaterial;
TextMesh textMesh = this.__textDuplicate.AddComponent<TextMesh>();
// Setup the text options
textMesh.characterSize = 0.1f;
textMesh.fontSize = 100;
textMesh.richText = false;
textMesh.offsetZ = 0.01f;
Font font = (Font)Resources.GetBuiltinResource(typeof(Font), "Arial.ttf");
textMesh.font = Instantiate(font) as Font;
}
My result looks like this:
Now, there are a number of issues here:
1) The text isn't alpha'd correctly. If I go into the inspector and set the font to None and then back to Arial again, sometimes it will correct itself.
2) The text is flipped horizontally. Why does this happen? The original geometry is Y up, Z towards camera.
3) This completely garbles my debug GUI text. Why would this happen if I'm using an instance of the Arial font instead of the original?
I guess it's pretty clear that my approach of programatically adding text to objects is wrong. Can anyone suggest a stable way of doing this?
Thanks, Ves
Your answer
Follow this Question
Related Questions
Replacing font of TextMesh issue 1 Answer
How to dynamically change a TextMeshProUGUI font in runtime ? 0 Answers
Changing font material alpha for just one clone 0 Answers
Text map problem with 3d text 1 Answer
How to Get a Char from his name ? 1 Answer