Book Image

Learning Unity Android Game Development

By : Thomas Finnegan
Book Image

Learning Unity Android Game Development

By: Thomas Finnegan

Overview of this book

<p>Unity 5 is a revolution in developing great games for Android that provides a great integration platform that works seamlessly with Unity 5, which means that games can be developed quicker and easier than ever before.</p> <p>Packed with a lot of examples, this book starts by helping you to understand all the great features that Unity 5 and Android have to offer. You will then create great games like Tic-Tac-Toe and the Monkey Ball game and also learn to enhance them. You will then expand the game's environment with lights and a skybox and learn to create enemies in a tank battle game. You will then explore the touch and tilt controls with the creation of a Monkey Ball clone.</p> <p>With the recreation of a game similar to Angry Birds, you will delve into configuring physics and options for a 2D game experience. Finally, you will get a complete experience by learning the optimization techniques needed to keep your games running smoothly.</p>
Table of Contents (16 chapters)
Learning Unity Android Game Development
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Preface

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

The first game that we will make is Tic-Tac-Toe. This game functions just like the classic paper version. Two players take turns filling a grid with their symbols and the first to make a line of the same three symbols wins. This 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, you will have all the understanding and the tools that are needed to add any interface that you might want to any game.

The next game that we will create is the Tank Battle game. In this 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 the many key points of creating games for the Android platform. We start it by creating a city and making the player's tank move around by using the controls about which we learned when we made the Tic-Tac-Toe game. We also create and animate the targets at which a player will shoot. 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 around the city and attack them when they are close.

The third game 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 explore some of the specific features of a 2D game and Unity's 2D pipeline, such as a parallax scrolling background and the use of sprites. We complete the chapter and the game with the creation of a level-selection menu and the saving of high scores.

Finally, we will create a Monkey Ball-style game. This game involves using the special inputs of a mobile device to control the movement of the ball and the player's interaction with the world. When a player's device is tilted, they will be able to guide the monkey around the level. When they touch the screen, they can do damage and eventually collect bananas that are scattered throughout the game. This game also shows you how to include the special effects that are necessary to complete the look of every game. We create explosions when bananas are collected and dust trails when our monkey moves around. We also add in sound effects for touching and exploding.

We wrap up the book by taking a look at optimization. We explore all the great features of Unity and even create a few of our own to make our game run as best 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 will have four great games that are just about ready for the 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 and explains why they are great choices for development. We also cover the setting up of the development environment and create a simple Hello World application for your device and emulators.

Chapter 2, Looking Good – The Graphical Interface, takes a detailed look at the graphical user interface. By creating a Tic-Tac-Toe game, you learn about the user interface while you make it pleasing to look at.

Chapter 3, The Backbone of Any Game – Meshes, Materials, and Animations, explores how you can utilize meshes, materials, and animations in Unity. Through the creation of a Tank Battle game, we cover the core of what players will see when they play the game.

Chapter 4, Setting the Stage – Camera Effects and Lighting, explains the camera effects and lighting options that are available in Unity. With the addition of shadows, lightmaps, distance fog, and a skybox, our Tank Battle environment becomes more dynamic. By utilizing special camera effects, we create extra feedback for players.

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

Chapter 6, Specialities of the Mobile Device – Touch and Tilt, covers the features that make the modern mobile device special. We create a Monkey Ball-style game to understand the touch interface and tilt controls.

Chapter 7, Throwing Your Weight Around – Physics and a 2D Camera, shows you how to create a clone of the Angry Birds game while taking a short break from the Monkey Ball game. Physics and Unity's 2D pipeline are also explored here.

Chapter 8, Special Effects – Sound and Particles, returns us to the Monkey Ball 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 Monkey Ball 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 the Android platform. As you have seen in the previous section, we will cover both the acquisition and installation of Unity and Android SDK in the first chapter. To get the most out of this book, you will need access to an Android-powered device; either a phone or tablet that will work well. Some sections of the book cover features that are only available in the Pro version of Unity. For simplicity's sake, we will assume that you are working on a Windows-powered computer. In addition, the code throughout the book is written in C#, though JavaScript versions of each chapter's project are available for reference. To fully utilize the models provided for each chapter's projects, you will need Blender, which is a free modeling program that is available at http://www.blender.org. You will also need a photo editing program; both Photoshop and Gimp are excellent choices. You will need both a modeling program, such as Blender, and an image editing program, such as Photoshop or Gimp, to create and work with your own content. We also recommend that you obtain a source by which to create or acquire audio files. All of the audio files provided by this book can be 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 using Unity 5.0 and Android L. 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 skill, this book will enable you to jump in and learn some concepts and standards for programming and game development.

Conventions

In this book, you will find a number of text styles 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: "The CheckVictory function runs through the possible combinations for victory in the game."

A block of code is set as follows:

public void NewGame() {
  xTurn = true;
  board = new SquareState[9];
  turnIndicatorLandscape.text = "X's Turn";
}

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, for example, in menus or dialog boxes, 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 disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's 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 at 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 from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. 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 better understand the changes in the output. You can download this file from: https://www.packtpub.com/sites/default/files/downloads/LearningUnityAndroidGameDevelopment_Graphics.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 could 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 to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted 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

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.