So, like a lot of people, I have been learning Unity’s new 2D workflow features, and since there is little to no documentation on how to use these new features, I will share my findings here.
My first experiences with Unity’s 2D workflow features have been positive, it is a lot easier to make things work in 2D now. However, it’s way to easy to fall back into the ‘old’ way of doing things. My biggest for instance is solving z-order issues with 2D objects.
Unity 4.3 added the concept of a sprite. A sprite is essentially made up of a quad with a pre-generated material that references your image and has a prebuilt shader to render it properly. In pre 4.3 you would have to use the Transform properties of the quad to set the z to a correct value in order to get the quad to render in the proper order. z values closer to your camera would render on top of items with z values farther away.
In 4.3 you don’t need to monkey with the z coordinate anymore. Unity has added the concept of a ‘sorting layer’. Unity already used layers for other purposes, so adding this to the layers functionality is really great.
So how do you use these features? Well, it’s really simple once you know where to look. When you add Sprite objects to your scene, Unity uses a Sprite Renderer component instead of the Mesh Renderer. The new Sprite Renderer component has two properties which control the layer your sprite is on, and it’s order within that layer.
You can see in the image, under the Inspector toolpane that there are properties for ‘Sorting Layer’ and ‘Order in Layer’. You can manage your layers by dropping down the list for layers and selecting ‘Add sorting layer’.
To arrange GameObjects within the layer just assign them different ordering values, with higher values being closer to the camera.
I hope this has helped you with your 2D games using Unity. I’ll keep posting my findings, let me know what you find out as well!