Book Image

Mastering Android Game Development with Unity

By : Siddharth Shekar
Book Image

Mastering Android Game Development with Unity

By: Siddharth Shekar

Overview of this book

Game engines such as Unity are the power-tools behind the games we know and love. Unity is one of the most widely-used and best loved packages for game development and is used by everyone, from hobbyists to large studios, to create games and interactive experiences for the Web, desktop, mobile, and console. With Unity's intuitive, easy-to-learn toolset and this book, it's never been easier to become a game developer. You will begin with the basic concepts of Android game development, a brief history of Android games, the building blocks of Android games in Unity 5, and the basic flow of games. You will configure an empty project for the Jetpack Joyride Clone Game, add an environment and characters, and control them. Next you will walk through topics such as particle systems, camera management, prefabs, animations, triggers, colliders, and basic GUI systems. You will then cover the basic setup for 3D action fighting games, importing models, textures and controlling them with a virtual on-screen joystick. Later you will set up Scene for 3D Configuration, create basic gameplays, and manage input controls. Next you will learn to create the interface for the main menu, gameplay, game over, achievements, and high score screens. Finally you will polish your game with stats, sounds, and Social Networking, followed by testing the game on Android devices and then publishing it on Google Play, Amazon, and OUYA Stores.
Table of Contents (15 chapters)
Title Page
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Customer Feedback
Preface

Basics of Unity game development


Before delving into the details of Unity3D and game development concepts, let's have a look at some of the basics of Unity 5.6 We will go through the unity interface, menu items, using assets, creating scenes, and publishing builds.

Note

This section is required for all new developers who have very little or no knowledge of Unity and want to learn basics of game development using Unity. If you are already familiar with Unity basics, you can skip this section.

Unity editor interface

When you first time launch Unity 5.6, you will be presented with an editor containing a few panels on left, right, and bottom of the screen. There's nothing to worry from these panels. The following image shows the editor interface when it's first launched:

Figure 1.7 Unity 5 Editor Interface at first launch

First of all, take the time to look over the editor and become a little familiar with it. The Unity editor is divided into different small panels and views that can be dragged around, resulting in a workspace that can be customized, according to the developer/designer's needs. Unity 5 comes with some pre-built workspace layout templates that can be selected from Layout drop-down menu in the top-right corner of the screen, as shown the following screenshot:

Figure 1.8 Unity 5 editor layouts

The layout currently displayed in the editor is the Default layout. You can select these layouts and see how the editor's interface changes and how different panels are placed in different positions in each layout. This book uses the 2 by 3 workspace layout for the game. 

The following screenshot shows the 2 by 3 workspace with the names of the views and panels highlighted:

Figure 1.9 Unity 5 2 by 3 layout with views and panel names

As you can see in the preceding screenshot, Unity editor contains different views and panels. Every panel and view has a specific purpose, which is described in the following section.

Scene View

Scene View is the whole stage for the game development, and it contains every asset in the game from a tiny point to any heavy 3D model. Scene View is used to select and position environments, characters, enemies, the player, camera, and all other objects that can be placed on the stage for the game. All those objects, which can be placed and shown in the game, are called as GameObjects. The scene view allows developers to manipulate game objects such as selecting, scaling, rotating, deleting, and moving. In simple words, Scene View is the interactive sandbox for the developers and designers. The Scene View provides some controls, such as navigation and transformation.

Transform tools

While developing games in Unity, you will place lots of game objects in the scene and their position, scale, and rotations, collectively called as transforms, are managed by transform tools. The following screenshot shows the transform tools:

Figure 1.10 Transform Tools

You can select any selected transform action from this toolbar and change the game object accordingly. The following figure shows the gizmo on the selected game object when a transform tool is selected:

Figure 1.11 Gizmos on game objects of transform Tools

These tools do exactly the same job as their names suggest; move for translation, rotate for rotation, and scale for scaling. The Rect tool on other side was introduced in Unity 4.3 when Unity got native 2D support and tools. This tool is only for 2D sprite objects for their position, scale, and rotations. You can also select these tools with keyboard shortcuts.

Scene View navigation

In the last section, we discussed how GameObjects can be transformed and navigated in the scene. But Unity being a 3D environment, it has an easy interface to view the scene from different angles, sides, and perspectives using mouse and keyboard shortcuts. You can observe the Scene Gizmo in the top-right corner of the Scene view. This gizmo is used to rotate the view according to the developer's needs. The following screenshot shows the gizmo of the scene:

Figure 1.12 Scene Gizmo for Scene View Navigation

Every view of the scene is shown in either perspective or isometric. There is also another view for the scene which we will discuss in the next section.

Scene View control bar

The control bar is shown at the top of the Scene View and it gives the developer more control to navigate through their scenes and create games easily. This bar includes options such as enabling/disabling gizmos, sounds, and selecting view modes. The important part of this bar is the 2D mode button, as shown in the following screenshot:

Figure 1.13 control bar of Scene View

The 2D mode button is a toggle button; when turned on; it disables the z-axis of the view and show the game from 2D perspective. It is highly used option while creating 2D games in Unity. On the right side of the bar, there is a text box for search. This lets developers search the game objects from the current scene and allows them to quickly work.

Game View

The Game View is the final representation of how your game will look when published and deployed on the target devices, and it is rendered from the cameras of the scene. This view is connected to the Play Mode navigation bar at the top of the whole Unity workspace, as shown in the following screenshot:

Figure 1.14 Play mode bar

When the game is played in the editor, this control bar gets changed into blue. A very interesting feature of Unity is that it allows developers to pause the game and code while running and developers can see and change the properties, transforms etc at runtime without recompiling whole game for quick workflow.

Game View control bar

Like scene view, game view also includes a control bar on top side of the view as shown in the following figure:

Figure 1.15 Game View Control Bar

The options perform the actions as their names suggest. The Free Aspect drop-down on the left side of the bar lets developers choose any specific resolution to test their games. These resolutions and drop down options vary on the selected platform. Developers can also add their own custom resolutions and screen sizes for their targeted devices. Unity also allows developers to specify aspect ratios as well to have an idea of how the game will run on various devices with the same aspect ratio. Unity is quite powerful and easily gives cross-platform support to make their games run better on most types of devices writing code only once.

Hierarchy View

The Hierarchy View is the first point to select or handle any GameObject in the scene. This contains every game object in the current scene. This is tree-type structure allowing developers to utilize parent and child concepts on the game objects easily. The following screenshot shows a simple Hierarchy View:

Figure 1.16 Hierarchy View

Project browser panel

This looks like a view, but it is called the Project browser panel. This panel is an embedded files directory in Unity and contains all the files and folders included in the game project. 

Following screenshot shows a simple Project browser panel:

Figure 1.17 Project browser panel

The left side of the panel shows a hierarchical directory, while rest of the panel is the files or as these are called assets in Unity. Unity represents these files with different icons to differentiate these according to their file types. These files can be sprite images, textures, model files, sounds and so on. You can search any specific file by typing in the search text box. On the right side of search box, there are button controls for further filters such as animation files, audio clip files, and so on.

Note

An interesting thing about Project browser panel is that if any file is not available in the assets, then Unity starts looking for it on Unity Asset Store and presents you with available free and paid assets.

Inspector panel

This is a most important panel for development in Unity. Unity structures the game in the form of game objects and assets. These game objects further contain components such as transforms, colliders, scripts, and meshes, and so on. Unity lets developers manage these components of each game object through the inspector panel.

The following screenshot shows a simple inspector panel of a game object:

Figure 1.18 Inspector Panel

These components vary in type including physics, mesh, effects, audio, and user interface. These components can be added to any object by selecting it from the component menu. The following screenshot shows the Component menu:

Figure 1.19 Components Menu

After covering some of the basics of the Unity, let's move on to the very first task developers do when creating a game; and that is creating an empty project. Let's discuss the configuration of empty projects in Unity for 2D games in the next section.