I’ve been trying to create a Text Mesh that should write out a text. The thing is that I can create the text, but the text does not have any letters, just squares that resembles letters.
The text does have a font and all the things neccessary(I believe?) to be able to write out text. If I change my font back and fourth IN THE UNITY UI the text works. But since I want to create the text by only using code, that is a problem.
Here is the code:
First I create the GO in a class and add TextScript.cs and feed with it some data. Then I create the text in TextScript.cs.
void CreateDamageText(Vector3 position, string text)
{
GameObject go = new GameObject("HitByPlayer:"+player+" DamageDone:"+text);
go.AddComponent<TextScript>();
TextScript tS = go.GetComponent<TextScript>();
tS.text = text;
tS.position = position;
}
void Start ()
{
gameObject.AddComponent("TextMesh");
gameObject.AddComponent("MeshRenderer");
gameObject.transform.position = new Vector3(position.x, position.y + 1, position.z);
gameObject.transform.eulerAngles = new Vector3(0, 0, 0);
TextMesh textMesh = gameObject.GetComponent(typeof(TextMesh)) as TextMesh;
textMesh.alignment = TextAlignment.Center;
textMesh.anchor = TextAnchor.MiddleCenter;
textMesh.fontSize = 128;
textMesh.transform.localScale = new Vector3(0.05f, 0.05f, 0.05f);
textMesh.text = text;
textMesh.font = GameController.globalFont;
}
What is wrong? It is driving me bonkers.
Thanks in advance