- Home /
3D Text appears over everything
My 3D text appears over everything in my game. If I have a wall in front of my text, I don't want it to appear. I've tried resolving this using the solution in the wiki here -> http://wiki.unity3d.com/index.php?title=3DText But this only seems to work for text created in the editor.
From what I can tell, my text object I create programmatically is identical to the 3D text object created using the editor. It has all of the same components anyway. The code I use to create the text looks like
public static GameObject CreateTextObject(Font font, Material mat)
{
GameObject fontObj = new GameObject();
TextMesh tm = fontObj.AddComponent<TextMesh>();
MeshRenderer mRenderer = fontObj.AddComponent<MeshRenderer>();
mRenderer.material = mat;
tm.font = font;
Shader zTextShader = Shader.Find("Resources/Shaders/zTextShader");
tm.renderer.material.shader = zTextShader;
tm.renderer.material.SetTexture("_MainTex", mat.mainTexture);
return fontObj;
}
font and mat are loaded using Resources.Load and are created as described in the wiki. zTextShader is just the shader from the wiki.
Has anyone been able to generate 3D text programmatically and have it render behind objects? If so, what did you do?
Answer by Owen-Reynolds · Jun 05, 2013 at 03:30 PM
The trick is changing the shader (the rest is boilerplate object assembling.) I'd imagine that the "zTextShader" has been modified and you either missed seeing it, or they forgot to mention it.
The original shader is named Font.shader. Inside of it, change where it says "ZTEST Always" to "ZTEST Less". Then, if you ever use the normal "over everything" 3DText, change the name (top line, in quotes. The GUI/ isn't required, but seems good to keep.)
Can get the shader by downloading Unity Default shaders (then grab the Font one, open and change it,)
Answer by homer_3 · Jun 05, 2013 at 10:39 PM
It ended up being an issue with multiple cameras. The text was being rendered in one camera and my wall was in another.
Your answer
Follow this Question
Related Questions
instantiate 3d text with different names - c# 1 Answer
Problems with 3D text 1 Answer
3D Text visible from/in x distance/place 0 Answers
Fading 3d text - only fades once 1 Answer