- Home /
3D Text Component hide from behind
Hi,
Is there a way to hide a 3D Text Component that is in "air" when the user look from behind? I'm not talking to hide when is behind an element like here: http://wiki.unity3d.com/index.php?title=3DText
So I have a 3D text up on the player, and from front is ok:
And from behind the text should not be visible:
I try with Transparent, but it give me a black color. How can I resolve this?
Thanks, Sorin
Answer by robertbu · Mar 04, 2014 at 09:55 AM
You could turn it off. Compare the Vector3.Dot() of the transform.forward of the camera with the transform.forward of the 3D Text. If the value is negative, then disable the renderer. Put something like this on your 3D Text.
#pragma strict
function Update() {
renderer.enabled = Vector3.Dot(transform.forward, Camera.main.transform.forward) > 0.0;
}
I was thinking on some shader, is there a shader that will work?
Take a look at the shader and instructions here:
http://wiki.unity3d.com/index.php/3DText
You would need to change 'Cull Off' to 'Cull Back'.
Thanks Robert! This I was searching for. It's working great!!! So now the script looks like this:
Shader "GUI/3D Text Shader" {
Properties {
_$$anonymous$$ainTex ("Font Texture", 2D) = "white" {}
_Color ("Text Color", Color) = (1,1,1,1)
}
SubShader {
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
Lighting Off Cull Back ZWrite Off Fog { $$anonymous$$ode Off }
Blend SrcAlpha One$$anonymous$$inusSrcAlpha
Pass {
Color [_Color]
SetTexture [_$$anonymous$$ainTex] {
combine primary, texture * primary
}
}
}
}