Introduction to Unity 2D

This introductory Unity tutorial will get you up and running with Unity 2D by creating a lunar landing game. By Ben MacKinnon.

Leave a rating/review
Download materials
Save for later
Share
You are currently viewing page 5 of 5 of this article. Click here to view the first page.

Fine Tuning Layers

However, there’s one problem. What about the sprites for the thruster animations (and the lander’s feet that normally hide behind the lander)? If you don’t set a specific Order in Layer number for these and for the Lander itself, you’ll see some odd rendering problems!

Lander-order-in-layer-conflict-problems

Change the Order in Layer property for the Lander itself to be 2. Select each Thruster child GameObject, as well as the LanderFeet GameObject, and set their Order in Layer values to 1.

When the lander touches down on the landing pad, the pad sinks down a little to show that you’ve landed. The landing pad and rock sprites overlap each other, so for the effect to look right, you’ll have to order the landing pad behind the rock.

Change the LanderObjective sprite to use the Rocks layer, and assign it an Order in Layer value of 0. Set the rock underneath the LanderObjective to use a Order in Layer value of 1:

LanderObjectiveAndRockUnderneath

Finally, click the Explosion prefab in the Prefabs folder and change its Sorting Layer to Player:

Cool folks don’t look at explosions. But we do!

set explosion prefab sorting layer

Click Play and test your piloting skills by picking up fuel supplies and touching down on the landing pad. Just be careful not to apply too much thrust in any one direction so that you avoid the rocks!

Nailed it! :]

Finished Landing

With enough practice, you’ll be as good at landing rockets as Space X! :]

Where to Go From Here?

Download the completed project by clicking the Download Materials button at the top or bottom of the tutorial.

You’ve covered most of the important 2D design features of Unity, and you have a fun little gravity lander game to show for it!

Why not take your game to the next level by adding in a cool replay feature? Follow along with this Creating a Replay System in Unity tutorial to learn how.

Or, if you’d like to try some more in-depth 2D animations and sprite effects, why not check out the Unity 2D Techniques: Build a 2D Pinball Game tutorial?

We hope you enjoyed this tutorial. If you have any questions or comments, please join the forum discussion below!