Building Flappy Bird in Unity
Unity is a great engine, but like all game engines it has a little learning curve. This tutorial is designed to take you through the entire process of building a 2D game in Unity that will run on the web, pc/mac, and mobile. By the time you complete this project, you’ll understand:
- The different areas of the Unity editor
- Importing Art
- Using the Physics system
- Handling Input
- Writing a little code (even if you’ve never written code before)
Let’s get started!
Importing the Art Package
Select Assets->Import Package->Custom Package…
Browse to the Art assets package. If you don’t have it, you can download it by clicking here.
You’ll be presented with a file list dialog. This dialog allows you to select which files in the package you want to import. By default, all files will be selected.
For now, click “Import”.
Next, focus your attention on the Hierarchy section of the editor. It should be in the top left corner and contain a single GameObject named “Main Camera”
Select the Main Camera by clicking on it.
Selected GameObjects in your Hierarchy will show blue. You can select any number of GameObjects at the same time. For now though, we only have one available to us, so let’s look over to the other side.
On the right we have the Inspector area. Here you can see or inspect details about your selected GameObjects. Notice that the inspector shows 5 components because we’ve selected the default camera object Unity creates for us. The 2 components you care about today are the Transform and the Camera.
Transform
EVERY GameObject in Unity has a Transform. The transform controls the objects Position, Rotation, and Scale.
-
Position - The location of the object in the world or relative to it's parent.
-
Rotation - The direction the object is facing.
-
Scale - The size of the object.
Camera
This component allows our game to render. This is the area we want to modify now.
First, try adjusting the “Background” value and notice how the background changes in the Game View (located in the center) or the Camera Preview.
To change the background, just click on the area showing the current color in the inspector. The default is blue.
Once you’ve found a water color you like, you need to make sure the Camera Perspective is set to Orthographic. (It should be by default, but we need to make sure)
Project View
It’s time to put something in our game. Look to the bottom of your editor where you’ll see the Project area.
Browse to the art folder and select the Fish
Drag the Fish to the Hierarchy.
You should see the fish in your Hierarchy and in your Scene or Game View.
You can toggle between the 2 views using the tabs, or drag them out to separate them
Play Mode
Now, I want you to hit the Play button and watch what happens!
If you’ve followed along so far, nothing should have happened. The Game View will automatically focus, but nothing should be moving.
Let’s make something happen…
With the Fish selected, hop over to the Inspector.
Click the big Add Component button.
Start typing and find the RigidBody2D.
You can alternatively browse to it under Physics2D.
The RigidBody2D component will make our GameObject (the Fish in this instance) interact with the games physics system. One of those interactions is gravity…
Let’s Play
First, I want you to think for a second. When you hit “Play” what do you expect will happen? Say it to yourself, then hit the button and see if you’re right.
If you thought the fish would fall, great. If not, don’t worry about it. Because our fish has a RigidBody, it uses gravity (unless Gravity Scale is set to 0). If there are no other forces acting on the object, the RigidBody will make it fall straight down.
In Part 2, we’ll start handling input and adding some additional force to keep the fish from falling away.
Continue To: Part 2 – Let’s Code!
Sign up here to be automatically notified about new posts