Book Image

Learning Unity 2D Game Development by Example

By : Venita Pereira
Book Image

Learning Unity 2D Game Development by Example

By: Venita Pereira

Overview of this book

<p>If you are looking for a guide to create 2D games using Unity, look no further. With this book, you will learn all the essentials of 2D game development by creating five real-world games in a step-by-step manner throughout the course of this book.</p> <p>Starting with a blank scene, you will learn all about the new Unity 2D toolset, which will enable you to bring your scene to life. You will create characters, make them move, create some enemies, and then write code to destroy them. After figuring out all the necessities of creating a game, this book will then assist you in making several different games: games with collision, parallax scrolling, Box2D, and more.</p> <p>By the end of this book, you will not only have created several small games, but you will also have the opportunity to put all your new-found knowledge into creating and deploying a larger, full game.</p>
Table of Contents (17 chapters)
Learning Unity 2D Game Development by Example
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

The ninja character


Our ninja character needs to be an animated sprite that loops infinitely. The position of the ninja will remain static as we will move the background and foreground to give the illusion of movement.

To create our character, we execute the following steps:

  1. Add a folder to Assets within the Project Browser named Ninja.

  2. Download and unzip the image NinjaSpriteSheet.png from http://freeartsprites.com/free-art/endless-runner/.

  3. Slice the sprite sheet into individual animation sprites.

  4. Create a sprite GameObject using the following image:

  5. Name the GameObject Ninja.

  6. We then go to Add component | Physics 2D | Box Collider 2D.

Running

As we are creating an endless runner, we, of course, need our ninja to run! To create a run animation, we do the following:

  1. Select the ninja from the hierarchy.

  2. Go to Window | Animation.

  3. Click on Create New Clip.

  4. Save it as Run.anim.

  5. Drag the following images into the timeline:

  6. Set the sample to 10 to speed up the animation so that the ninja is running quickly.

Jump...