Hi,
I want to add a TextMesh to my GO, but as soon as I add it, it makes the GO become invisible and the TextMesh is invisible too. Only their casted shadows are displayed. However I can still drag the invisible GO around with it TextMesh. (TextMesh shadow is moving with drag)
Here is how I try to do this:
public void displayMarkerText(GameObject marker)
{
Font myFont = Resources.Load("Assets/Ophta3d/Fonts/Arial") as Font;
TextMesh textMesh = marker.AddComponent("TextMesh") as TextMesh;
textMesh.text = "TEST";
textMesh.font = myFont;
textMesh.transform.position = marker.transform.position;
textMesh.renderer.material.color = Color.blue;
}
Is there something I am doing wrong?
Thanks
Greg
Your dir structure for finding your font with Resources.Load is incorrect:
The Directory you’re looking for is relative to the /Assets/Resources folder, I suggest you create a folder named Resources directly in /Assets and then put the font file directly in there:
Then you just load the font in with Resources.Load(“fontfilename”)
Ok so I corrected the path issue, but it still the same. Only the shadow of the text that appears.
And there are no errors displayed in the console.
Thanks
Greg
For testing purposes I created a 3D Text in the editor to see its components and what I realized is that when i create my text mesh in the script it has no mesh renderer whereas the 3D text in the editor has one. So probably thats why my scripted text mesh doesn’t appear.
So do I have to add a mesh renderer to my text mesh in the script?
Thanks
Greg
I am on a different approach that gives a better result, but still there is something I don’t understand.
So what I do is to put a GO with a text mesh on it on the scene (without any text) and thats what I instantiate for every marker I want and I set the text at this moment. I also give the text color the same color as the marker’s color, but after the first instantiate, the text looses its material so it becomes invisible. The first gets the color correctly.
If I don’t set the color, Instantiate work as many times I want, but the color is white for all the texts.
Anyone know a solution to how to give a different color to every instance without “erasing” the material?
Thanks
Greg
public void createMarkerText(GameObject marker, int index)
{
GameObject tHolder = GameObject.Find("textHolder");
GameObject newTextHolder = Instantiate(tHolder, marker.transform.position, marker.transform.rotation) as GameObject;
newTextHolder.name = marker.name;
TextMesh newText = newTextHolder.GetComponentInChildren(typeof(TextMesh)) as TextMesh;
newText.text = "TEST";
newText.transform.localScale = new Vector3(0.01f, 0.01f, 0.01f);
newText.transform.position = marker.transform.position;
//newText.renderer.material.color = marker.renderer.material.color;
newText.transform.RotateAround(Vector3.up, 3.0f);
newText.transform.RotateAround(Vector3.left, 1.0f);
newText.transform.parent = marker.transform;
markerObjList[index].textHolder = newTextHolder;
}