Shaders: How to ztest against specific layers?

I made this shader to overlay a color when my player’s mesh is hidden by other geometry in the scene:

SubShader 
     { 
         Tags { "Queue"="Overlay+1" }
 
         Pass
         {
             ZWrite Off
             ZTest Greater
             Lighting Off
             Cull off
             Color [_ColorInvisible]
         }
 
         Pass 
         {
             ZTest Less
             Material {
                Diffuse [_Color]
                Ambient (0,0,0,0)
            }
             Lighting On
             SeparateSpecular On
             
             SetTexture [_MainTex] {combine texture * primary DOUBLE, texture * primary}
         } 
     }

The shader is working great but I’m unable to make it work only with specific layers:

I would like to make the overlay only when my player (wich has the above shader applied) is behind objects on a specific layer (i.e Wall layer).

How can i achieve this?

Thanks in advance.

I think, you should set sequence of drawing of shaders: at first walls, then the player, further all that remained. For wall and some object use “Queue” = “Geometry” (default). For player change to “Queue” = “Geometry + 10”. For all remained object use, for example, “Queue” = “Geometry + 100”. For more information about Queue see docs. I hope that it will help you.