Hi All, I have a little problem I'm painting text with TextMesh. It is created using the position of a node in a 3D space. It is working well the position, but the text doesn't appears in the screen, I only see white squares that looks similar to the text in size and shape. What is my mistake? Thanks for the help Code (CSharp): public void paintText () { for (int i = 1; i < gm.nodeCount; i++) { if (gm.Nodes [i].weight_node > 1.5) { TextMesh n_text = new GameObject ("Text_" + i).AddComponent ("TextMesh") as TextMesh; n_text.transform.parent = gameObject.transform; n_text.GetComponent<MeshRenderer> ().castShadows = false; n_text.GetComponent<MeshRenderer> ().receiveShadows = false; n_text.transform.localPosition = gm.Nodes [i].newPosition; Material material = new Material (Shader.Find ("Particles/Alpha Blended")); n_text.renderer.material = material; n_text.renderer.material.SetColor ("_TintColor", nodeColor); UnityEngine.Object.Destroy (n_text.GetComponent<Rigidbody> ()); UnityEngine.Object.Destroy (n_text.GetComponent<MeshCollider> ()); n_text.font = newFont; n_text.text = gm.Nodes [i].currentRegionIndex; } } }
Probably when you change the material of the textmesh, it is losing all the font's graphic data. Solution: don't do that. Change n_text.color instead of replacing the whole material. There was a bug where changing the font at runtime could cause similar issues. I don't think that's your problem here, though, plus I haven't (personally) seen that bug in a few versions.
I still don't find the solution. Is Start() I call the font like this: newFont = Resources.Load("verdana", typeof(Font)) asFont; And the code compiles, then the object also show the font, but I need to manually change to none and then back to "verdana" and then it works! Don't get it I don't care about verdana font, I also tried with Helvetica, Arial, and the problem is the same. Thanks for the help Code (CSharp): public void paintText () { for (int i = 1; i < gm.nodeCount; i++) { if (gm.Nodes [i].weight_node > 1.5) { TextMesh n_text = new GameObject ("Text_" + i).AddComponent ("TextMesh") as TextMesh; n_text.font = newFont; n_text.transform.parent = gameObject.transform; n_text.GetComponent<MeshRenderer> ().castShadows = false; n_text.GetComponent<MeshRenderer> ().receiveShadows = false; n_text.transform.localPosition = gm.Nodes [i].newPosition; //Material material = new Material (Shader.Find ("Particles/Alpha Blended")); //n_text.renderer.material = material; //n_text.renderer.material.SetColor ("_TintColor", nodeColor); //UnityEngine.Object.Destroy (n_text.GetComponent<Rigidbody> ()); //UnityEngine.Object.Destroy (n_text.GetComponent<MeshCollider> ()); n_text.fontSize = 12; n_text.richText = true; n_text.fontStyle = FontStyle.Normal; n_text.text = gm.Nodes [i].currentRegionIndex; } } }
Now I tried with Material material = (Material)Resources.Load ("verdana/Font Material",typeof(Material)); n_text.renderer.materials[0] = material; And it creates the material but is not the correct one....
I've never tried setting its font by code, alas. So I'm not sure how it responds and can't really offer any further help.
Resolved with: n_text.transform.parent = gameObject.transform; n_text.renderer.material = n_text.font.material;