(转载)Unity3d中3D Text对模型的穿透显示

Unity3D中使用3D Text(Text Mesh)时,如何让场景中的物体和3D Text有正确的遮挡关系。由于3D Text默认材质是(Font Material),他的shader是GUI/Text Shader,自然也就有了GUI的穿透特性,所以我们使用自定义材质就可以解决这个问题了。 
1、新建材质,并将如下shader设置给它

Shader "Custom/3D Text Shader" {
    Properties {
        _MainTex ("Font Texture", 2D) = "white" {}
        _Color ("Text Color", Color) = (1,1,1,1)
    }


    SubShader {
        Tags{ "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
        Lighting Off Cull Off ZWrite On Fog { Mode Off }
        Blend SrcAlpha OneMinusSrcAlpha
        Pass {
            Color [_Color]
            SetTexture [_MainTex] {
                combine primary, texture * primary
            }
        }
    }
}

 

 

2、导入一个字体,并将Character设置为Unicode。并将生成的图片设置给Shader 
这里写图片描述 
这里写图片描述 
3、将3D Text的材质替换成自定义的材质 
这里写图片描述 
注意:如果要调整字体颜色,3D Text中的Color属性已经失效,需要去调整那个自己建的材质球的Text Color;

 

转载:http://blog.csdn.net/honey199396/article/details/72742866

posted @ 2017-06-24 14:26  m_f_s  阅读(1167)  评论(0编辑  收藏  举报