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.
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Contents
Introduction to Unity 2D
35 mins
- Getting Started
- Sprites in Unity
- Sprite Modes
- Sprite Editing
- Slicing Spritesheets
- Custom Slicing
- Assigning Sprites to the Lander
- The 2D Camera and Pixels Per Unit
- A Word on Pixels Per Unit
- A Galaxy To Be Proud Of
- An Increase in Size
- Textures
- 2D Colliders and Physics
- Colliding With Objects
- A Quick Lesson on Physics Components
- Colliding Polygons
- A Few Other Things
- Lander Animation
- Unity Animation 101
- An Animator Controller for Thrusters
- Working on the Timeline
- Configuring the Animation Controller
- Sprite Sorting and Layers
- Time to Add Some Layers
- Fine Tuning Layers
- Where to Go From Here?
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!
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:
Finally, click the Explosion prefab in the Prefabs folder and change its Sorting Layer to Player:
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!
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!