unity shader : Applying ZOrder to sprite renderer conditionally

71686-vv.png

here’s scene object info of above figure. all of object’s renderer is ‘SpriteRenderer’, and Material is ‘Sprites-Default’.

[A (Car)] OrderInLayer : 302 Local Z Position : -9.8

[B (Land)] OrderInLayer : 270 Local Z Position : -9

[C1, C2 (Land)] OrderInLayer : 300 Local Z Position : -10

[D (Land)] OrderInLayer : 330 Local Z Position : -11

I hope that you do not obstruct the ‘D’ is ‘A’ in the above situation.

But such a situation can not use OrderInLayer.

So I’m not sure at all that you will use the same shader.

Help!

1 Answer

1

D is appearing on top of the car because it has a higher order in the sorting layer.

Note that if you’re creating a 2D game with an orthographic camera, don’t use Z to sort your objects. Place them all on a single plane (Z=0, for convenience) and then use sorting layers and order in layer to sort them.