When building a 2D game in Unity3D. We need to specify which items will be rendered above which item.
We can do it by specifying the distance of the sprite from the camera but Unity provides a better way of doing this through the use of Sorting Layers.
Sorting Layers are used to determne the rendering order of the sprites regardless of the distance from the camera.
We can assign a sprite or a group of sprites to a sorting layer. These Sorting Layers are given a sorting order.
When we render a sprite we can also secify it's order within a sorting layer.
Sorting Layers Can be Found in the Edit Menu -> Project Settings -> Tags and Layers
From Sprite component Select -> Sorting Layer -> Add Sorting Layer
After the sorting layer panel is open, we can Add, Delete and Re-arrange sorting layers. There is a default layer that cannot be remover but it can be rearranged.
We can assign a sorting layer to a sprite through it's drag and drop Layer menu as shown below.
Sorting Layers are rendered in the order of top to bottom in the sorting layer list. The first item is drawn in the back while the last item at the top.
It is to be noted that Sorting Layers and Order in layer are Globally available to all renderers in Unity