0
\$\begingroup\$

I have a 2-d game that I am making, using 3-d assets, including TextMeshes for text. I have decided that in some instances, I would like to have the TextMesh appear behind objects in the foreground. The below is one such example.

enter image description here

It seems that the TextMesh is always in front. I have tried a number of things to get the text between the map and object layers, with no success. These include:

  • Moving the text between the map and object.
  • Changing the SortingLayers and SortingOrder. The map, objects, and labels are on 3 different layers, with the Objects being the highest layer, the map the lowest, and default and label in between.
  • Using a perspective camera, not orthographic.

Any ideas as to what else could be going on? Thanks!

How can I make the TextMesh appear that isn't on the top layer? Thanks!

\$\endgroup\$
0
\$\begingroup\$

The answer is fairly complex, and involves 2 key things. Note that I used this reference to help me.

  1. Create a custom text shader. There are two examples given, I chose this one, which is for one sided text, which I believe is more common.

    Shader "GUI/3D Text Shader - Cull Back" {
        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 Back ZWrite Off Fog{ Mode Off }
    
            Blend SrcAlpha OneMinusSrcAlpha
            Pass{
                Color[_Color]
                ColorMaterial AmbientAndDiffuse
                SetTexture[_MainTex]{
                    combine primary, texture * primary
                }
            }
        }
    }
    
  2. This shader should be applied to a material. The texture should be the texture of the font (Must download a font).

This allowed me to do this (Still working on what text to use exactly)

enter image description here

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.