Z-Depth

Positioning our objects with the Translate tool will help us set up our level and accurately position objects in the Scene. But in a 2D setup this will only help us to place them along the X-axis (horizontal) and Y-axis (vertical). This will work for most everything, but we will want to have some depth to our levels. We want to have some dimension and balance to our world so it doesn’t appear flat. Sprites like clouds moving behind our player and allowing the player to walk in front of hills will help add a touch of realism, even though it is 2D.

In a 2D game using Unity, we can still control the Z-depth using the selected sprite’s Sorting Layer and Order in Layer attributes. These can be found on the Sprite Renderer of your Sprite GameObject. ...

Get Learning 2D Game Development with Unity®: A Hands-On Guide to Game Creation now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.