Book Image

Unity Android Game Development by Example Beginner's Guide

By : Thomas James Finnegan
Book Image

Unity Android Game Development by Example Beginner's Guide

By: Thomas James Finnegan

Overview of this book

Powerful and continuing to grow, the mobile market has never been bigger and more demanding of great games. Android continues to prove itself as a strong contender in this challenging market. With Unity 3D, great games can be made for Android quickly and easily. With its great deployment system, the Android platform is now only one click away. Unity Android Game Development by Example Beginner's Guide dives straight into making real, fully-functional games, with hands-on examples and step-by-step instructions to give you a firm grounding in Unity 3D and Android. Everything necessary for creating a complete gaming experience is covered and detailed throughout the course of this book. Using clear and practical examples that progressively build upon each other, this book guides you through the process of creating games in Unity for Android. Start by learning about all the great features that Unity and Android have to offer. Next, create a Tic-Tac-Toe game while learning all about interfaces. After that, learn about meshes, materials, and animations with the creation of a tank battle game. You will then learn how to expand your game's environment with the addition of shadows and a skybox. Adding on this, you will also learn how to expand the tank battle by creating enemies and using path finding to chase the player. Next, explore touch and tilt controls with the creation of a space fighter game. Then, learn about physics while recreating the most popular mobile game on the market. You will then expand the space fighter game with the addition of all the special effects that make a game great. Finally, complete your experience by learning the optimization techniques required to keep your games running smoothly. While Unity is available for both Mac and Windows, the book is presented working from a Windows environment. Programming in Unity is possible in C#, JavaScript, and Boo. This book will be working in C# and the final projects will be provided in C# and JavaScript. From nothing to a fully-featured mobile game, Unity Android Game Development by Example Beginner's Guide takes you through everything it takes to create your next game for the Android platform.
Table of Contents (17 chapters)
Unity Android Game Development by Example Beginner's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

In this book, we explore the ever-expanding world of mobile game development. Using Unity 3D and the Android SDK, we will learn how to create every aspect of a mobile game. Every chapter explores another piece of the development puzzle. Exploring the special features of development with mobile platforms, every game in the book is designed to increase your understanding of these features. We also finish the book with a total of four complete games and all of the tools we need to create many more.

The first game that we make is Tic-tac-toe. This game functions just as the classic paper version. Two players take turns filling a grid with their symbols; the first to make a line of three wins. It is the perfect game for us to explore the graphical interface options that we have in Unity. By learning how to add buttons, text, and pictures to the screen here, we have all of the understanding and tools needed to add any interface that we might want to any game.

The next game that we create is the Tank Battle game. The player takes control of a tank to drive around a small city and shoot targets and enemies. This game spans three chapters, allowing us to explore many key points of creating games for the Android platform. We start by creating a city and making the player's tank move around, using controls that we learned about when making the Tic-tac-toe game. We also create and animate the targets that the player will shoot at. In the second part of this game, we add some lighting and special camera effects. By the end of the chapter, the environment looks great. In the third part of the game's creation, we create some enemies. Using the power of Unity, these enemies chase the player throughout the city, and attack when they are close.

The third game to be completed is a simple clone of a popular mobile game. Using the power of Unity's physics system, we are able to create structures and throw birds at them. Knock down the structures to gain points, and destroy the target pigs to win the level. We also take the time to explore some of the specific features of a 2D game, such as a parallax scrolling background, and how they can be achieved in Unity. We complete the chapter and the game with the creation of a level selection menu.

Finally, we create the Space Fighter game. This game involves using the special inputs of a mobile device to control the player's ship. As the player's device is tilted, they will be able to steer the ship. When they touch the screen, they can shoot at the enemy ships and asteroids. The second part of this game involves including the special effects that complete the look of every game. We create explosions when ships are destroyed, and engine trails for the ships. We also add the sound effects for shooting and exploding.

The book wraps up with a look at optimization. We explore all of the great features of Unity, and even create a few of our own to make our game run as best as it can. We also take a little bit of time to understand some things that we can do to minimize the file size of our assets while maximizing their look and effect in the game. At this point, our journey ends, but we have four great games that are just about ready to go to market.

What this book covers

Chapter 1, Saying Hello to Unity and Android, explores the feature lists of the Android platform and the Unity 3D game engine, covering why they are great choices for development. We will also cover setting up the development environment, and create a simple Hello World application for your device and emulators.

Chapter 2, Looking Good ­– Graphical Interface, takes a detailed look at the graphical user interface. By creating a Tic-tac-toe game, we learn about the user interface while making it pleasing to look at.

Chapter 3, The Backbone of Any Game ­– Meshes, Materials, and Animations, explores meshes, materials, and animations. Through the creation of a Tank Battle game, we cover the core of what players will see when playing.

Chapter 4, Setting the Stage ­– Camera Effects and Lighting, explains about the camera effects and lighting. With the addition of shadows, lightmaps, distance fog, and a skybox, our Tank Battle environment becomes more dynamic. Utilizing special camera effects, we create extra feedback for the player.

Chapter 5, Getting Around ­– Pathfinding and AI, shows the creation of mobile enemies in our Tank Battle game. We explore pathfinding and AI to give players a target more meaningful than a stationary dummy.

Chapter 6, Specialties of the Mobile Device ­– Touch and Tilt, covers the features that make the modern mobile device special. We create a Space Fighter game to understand the touch interface and tilt controls.

Chapter 7, Throwing Your Weight Around ­– Physics and a 2D Camera, shows the creation of a clone of Angry Birds after taking a short break from the Space Fighter game. Physics and a 2D camera effect are explored here.

Chapter 8, Special Effects ­– Sound and Particles, returns to the Space Fighter game to add special effects. The inclusion of sound effects and particles allows us to create a more complete game experience.

Chapter 9, Optimization, covers optimization in Unity 3D. We cover the benefits and costs of making our Tank Battle and Space Fighter games as efficient as possible.

What you need for this book

Throughout this book, we will be working with both the Unity 3D game engine and Android. As you can see in the previous section, we will cover both the acquisition and installation of Unity and the Android SDK in Chapter 1, Saying Hello to Unity and Android. To get the most of this book, you will need access to an Android-powered device; either a phone or tablet will work well. For simplicity's sake, we will assume that you are working on a Windows-powered computer. Also, the code throughout the book is written in C#, though JavaScript versions of each chapter project are available for reference. To fully utilize the models provided for the chapter projects, you will need Blender, a free modeling program available at http://www.blender.org. To reach all of the challenges, you will need to make use of either Blender or another modeling program that you are comfortable with, for example, a photo-editing program; Photoshop is a common choice, and a source for the creation or acquisition of audio files. All of the audio files provided by this book were found at http://www.freesound.org.

Who this book is for

This book will be optimal for readers who are new to game development and mobile development with Unity. Readers who learn best with real-world examples rather than dry documentation will find every chapter useful. Even if you have little or no programming skills, this book will make a great place to jump in and learn some concepts and standards for programming.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "If during the build process, Unity complains about where the Android SDK is, select the android-sdk folder inside the location where it was installed."

A block of code is set as follows:

public void OnGUI() {
  GUILayout.Label("Hello World");
}

Any command-line input or output is written as follows:

adb kill-server
adb start-server
adb devices

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "Follow that up by clicking on the Download the SDK Tools for Windows button".

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title in the subject of your message.

If there is a topic that you have expertise in, and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books that you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support, and register to have the files e-mailed directly to you.

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you understand the changes in the output better. You can download this file from: http://www.packtpub.com/sites/default/files/downloads/2014OT_Images.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration, and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted, and the errata will be uploaded on our website or added to any list of existing errata under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.