Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Unity Android Game Development by Example Beginner's Guide
Unity Android Game Development by Example Beginner's Guide

Unity Android Game Development by Example Beginner's Guide: Absolute beginners to designing games for Android will find this book is their passport to quick results. Lots of handholding and practical exercises using Unity 3D makes learning a breeze.

eBook
$19.99 $28.99
Paperback
$48.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Unity Android Game Development by Example Beginner's Guide

Chapter 2. Looking Good – Graphical Interface

In the previous chapter, we covered the features of Unity and Android. We also discussed the benefits of using them together. After we finished installing a bunch of software and setting up our devices, we created a simple Hello World application to confirm that everything was connected correctly.

This chapter is all about Graphical User Interface (GUI). We will start by creating a simple Tic-tac-toe game, using the basic pieces of GUI that Unity provides. Following that we will discuss Unity's GUI Styles and GUI Skins. Using what we learned, we will improve the look of our game. Also, we will explore some tips and tricks for handling many different screen sizes of Android devices. Finally, we will learn about a much quicker way to put our games on the device, which was covered in the previous chapter. With all that said, let's jump in.

In this chapter, we will cover the following topics:

  • User preferences
  • Buttons and...

Creating a Tic-tac-toe game

The project for this chapter is a simple Tic-tac-toe-style game, similar to what any of us might play on paper. As with anything else, there are several ways you could make this game. We are going to use Unity's GUI system, in order to better understand how to create a GUI for any of our other games.

Time for action – creating Tic-tac-toe

The basic Tic-tac-toe game involves two players and a 3 x 3 grid. The players take turns filling X's and O's. The player who first fills a line of three squares with his/her letter wins the game. If all squares are filled without a player achieving a line of three, the game is a tie. Let's perform the following steps to create our game:

  1. The first thing to do is to create a project for this chapter. So, start up Unity and we will do just that.
  2. If you have been following along so far, Unity should boot up into the last project that was open. This isn't a bad feature, but it can become extremely annoying. Think of it like this: you have been working on a project for a while and it has grown large. Now you need to quickly open something else, but Unity defaults to your huge project. If you wait for it to open before you can work on anything else, it can consume a lot of time. To change this feature, go to the top of the Unity window...

Finishing the game

If you didn't want to go through the process of building the application and putting it on your device, it is still possible for you to try out interacting with the buttons, and touching them with your fingers. In Chapter 1, Saying Hello to Unity and Android, we installed the application, Unity Remote. Plug the device into your computer and start it up; when you click on Play in the Unity Editor, you should see the game running on your device. If you can see the game playing in the Unity Editor but not on the device, just restart Unity. Make sure to save it; it would be awful to lose all of your hard work.

Undoubtedly the first thing you will notice when using Unity Remote is that the game doesn't look good. It is almost certainly stretched and pixelated. If it doesn't concern you now, don't worry, it gets worse when the project becomes more complicated. Now, before you start freaking out, grumbling about why you had to install such a useless program...

Time for action – finish creating the game

Let us finish the creation of our game by creating an opening screen. We will then add some checks to stop players from selecting squares more than once. Follow that with a check to see if anyone won and finally display a game over screen. With that, the game will be ready for us to make it look great.

Let's perform the following steps for finishing our game:

  1. We will do all this by first creating another script like our SquareState script. Create the new GameState script and clear out the default contents. Add the following code snippet and we will have the values needed to track the current state of our game:
    public enum GameState {
      Opening,
      MultiPlayer,
      GameOver
    }
  2. We now need to update our TicTacToeControl script. For starters, because we want to be able to play multiple games, add the NewGame function to the script. This function initializes our control variables so that we can start a fresh game with a clear board. It will not...

GUI Skins and GUI Styles

GUI Styles are how we change the look and feel of GUI elements, buttons, and labels in Unity. A GUI Skin contains several GUI Styles and allows us to change the look of the entire GUI without explicitly defining GUI Styles for each element. To create a GUI Skin, right-click in the Project window of the Unity Editor, just as with creating a new script. Go to Create but, instead of selecting Script, go to the bottom and select GUI skin. Selecting this option will create the new GUI Skin and let us name it to GameSkin. By looking at our GameSkin in the Inspector window, you can see what we have to work with.

GUI Skins and GUI Styles
  • At the top is a Font attribute. By importing font files to your project and placing one here, you can change the default font used by text in the whole game.
  • Under that is a long list of GUI elements, including our good friends Button and Label. These are all GUI Styles and coincide with the GUI functions that we use to draw things on screen. For example, unless...

Creating a Tic-tac-toe game


The project for this chapter is a simple Tic-tac-toe-style game, similar to what any of us might play on paper. As with anything else, there are several ways you could make this game. We are going to use Unity's GUI system, in order to better understand how to create a GUI for any of our other games.

Time for action – creating Tic-tac-toe


The basic Tic-tac-toe game involves two players and a 3 x 3 grid. The players take turns filling X's and O's. The player who first fills a line of three squares with his/her letter wins the game. If all squares are filled without a player achieving a line of three, the game is a tie. Let's perform the following steps to create our game:

  1. The first thing to do is to create a project for this chapter. So, start up Unity and we will do just that.

  2. If you have been following along so far, Unity should boot up into the last project that was open. This isn't a bad feature, but it can become extremely annoying. Think of it like this: you have been working on a project for a while and it has grown large. Now you need to quickly open something else, but Unity defaults to your huge project. If you wait for it to open before you can work on anything else, it can consume a lot of time. To change this feature, go to the top of the Unity window and click on Edit followed...

Finishing the game


If you didn't want to go through the process of building the application and putting it on your device, it is still possible for you to try out interacting with the buttons, and touching them with your fingers. In Chapter 1, Saying Hello to Unity and Android, we installed the application, Unity Remote. Plug the device into your computer and start it up; when you click on Play in the Unity Editor, you should see the game running on your device. If you can see the game playing in the Unity Editor but not on the device, just restart Unity. Make sure to save it; it would be awful to lose all of your hard work.

Undoubtedly the first thing you will notice when using Unity Remote is that the game doesn't look good. It is almost certainly stretched and pixelated. If it doesn't concern you now, don't worry, it gets worse when the project becomes more complicated. Now, before you start freaking out, grumbling about why you had to install such a useless program, you must understand...

Time for action – finish creating the game


Let us finish the creation of our game by creating an opening screen. We will then add some checks to stop players from selecting squares more than once. Follow that with a check to see if anyone won and finally display a game over screen. With that, the game will be ready for us to make it look great.

Let's perform the following steps for finishing our game:

  1. We will do all this by first creating another script like our SquareState script. Create the new GameState script and clear out the default contents. Add the following code snippet and we will have the values needed to track the current state of our game:

    public enum GameState {
      Opening,
      MultiPlayer,
      GameOver
    }
  2. We now need to update our TicTacToeControl script. For starters, because we want to be able to play multiple games, add the NewGame function to the script. This function initializes our control variables so that we can start a fresh game with a clear board. It will not do very well...

GUI Skins and GUI Styles


GUI Styles are how we change the look and feel of GUI elements, buttons, and labels in Unity. A GUI Skin contains several GUI Styles and allows us to change the look of the entire GUI without explicitly defining GUI Styles for each element. To create a GUI Skin, right-click in the Project window of the Unity Editor, just as with creating a new script. Go to Create but, instead of selecting Script, go to the bottom and select GUI skin. Selecting this option will create the new GUI Skin and let us name it to GameSkin. By looking at our GameSkin in the Inspector window, you can see what we have to work with.

  • At the top is a Font attribute. By importing font files to your project and placing one here, you can change the default font used by text in the whole game.

  • Under that is a long list of GUI elements, including our good friends Button and Label. These are all GUI Styles and coincide with the GUI functions that we use to draw things on screen. For example, unless otherwise...

A prettier form of Tic-tac-toe


Finally, we get to put what we learned about GUI Skins and GUI Styles into action and make our game look better. Or, at least make the game look like it isn't using default assets. Whatever your artistic talents, you will need to find or create a few images to continue following along.

Time for action – styling the game


If you do not want to look far, the assets used for this chapter are found along with the resources for the book. All of the needed images are available, and they will work just well, until you have an opportunity to create some of your own.

  1. First, we need five small textures: ButtonActive, ButtonNormal, ONormal, XNormal, and Title. To create these, you will have to use a separate photo-editing program or use the ones supplied with the included projects.

  2. The easiest way to get the images into your Unity project is to simply save them into the Assets folder that is created when you create a new project. Alternatively, you can go up to the top and click on Assets followed by Import New Asset. This will open a file browser and let you navigate to the asset you want. When you have found the asset you desire to import and have clicked on the Import button, a copy of the asset is put in your project. Unity will not move or remove files that exist outside of the...

Left arrow icon Right arrow icon

Key benefits

  • Enter the increasingly popular mobile market and create games using Unity 3D and Android
  • Learn optimization techniques for efficient mobile games
  • Clear, step-by-step instructions for creating a complete mobile game experience

Description

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.

Who is this book for?

Great for developers new to Unity, Android, or both, this book will walk you through everything you need to know about game development for the Android mobile platform. No experience with programming, Android, or Unity is required. Most of the assets used in each chapter project are provided with the book, but it is assumed that you have some access to basic image and model creation software. You will also need access to an Android powered device.

What you will learn

  • Set up a development environment to work with both Unity and Android
  • Import and work with the basic building blocks of a game: meshes, materials, and animations
  • Utilize particles and sound effects to provide feedback to the player
  • Adjust camera effects and game logic to create 2D games
  • Interface with touch and tilt inputs to create custom control systems
  • Set up path finding to create intelligently moving characters
  • Successfully create custom graphical interfaces
  • Set up and utilize physics to create a mobile game classic
  • Create dynamically lit scenes using lightmaps
  • Understand the best choices for optimizing a game for the mobile platform

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Dec 23, 2013
Length: 320 pages
Edition : 1st
Language : English
ISBN-13 : 9781849692014
Vendor :
Unity Technologies
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Dec 23, 2013
Length: 320 pages
Edition : 1st
Language : English
ISBN-13 : 9781849692014
Vendor :
Unity Technologies
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 146.97
Unity 4.x Game Development by Example: Beginner's Guide
$48.99
Unity Android Game Development by Example Beginner's Guide
$48.99
Unity Multiplayer Games
$48.99
Total $ 146.97 Stars icon
Banner background image

Table of Contents

11 Chapters
1. Saying Hello to Unity and Android Chevron down icon Chevron up icon
2. Looking Good – Graphical Interface Chevron down icon Chevron up icon
3. The Backbone of Any Game – Meshes, Materials, and Animations Chevron down icon Chevron up icon
4. Setting the Stage – Camera Effects and Lighting Chevron down icon Chevron up icon
5. Getting Around – Pathfinding and AI Chevron down icon Chevron up icon
6. Specialties of the Mobile Device – Touch and Tilt Chevron down icon Chevron up icon
7. Throwing Your Weight Around – Physics and a 2D Camera Chevron down icon Chevron up icon
8. Special Effects – Sound and Particles Chevron down icon Chevron up icon
9. Optimization Chevron down icon Chevron up icon
A. Pop Quiz Answers Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.9
(15 Ratings)
5 star 46.7%
4 star 26.7%
3 star 6.7%
2 star 6.7%
1 star 13.3%
Filter icon Filter
Top Reviews

Filter reviews by




Belinda Feb 23, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Unity Android Game Development by Example Beginner’s Guide by Thomas Finnegan is a comprehensive introduction to Unity Development in general and Android development specifically. I would not recommend it to an unexperienced first-time game developer, but with only some basic experience Finnegan’s set of four tutorial games are a great read with plenty of useful information about all aspects of Unity Android development, including 2D and 3D games.The book covers scripting in the C# language and does a decent job at explaining the logic of most written code. Each exemplar game introduces new concepts and the difficulty curve slowly and consistently climbs until the last chapter gives valuable insights into game optimization. Some discussed features require a Unity Pro license to get maximum value out of the book. Despite sometimes almost reading like a Unity ad, I can recommend this book, as it currently is the most comprehensive and up-to-date introduction to Unity Android development.
Amazon Verified review Amazon
Oleg Apr 10, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Great book, very easy to follow, almost no typos or errors!Sometimes quite complex scripting but not too complex though.Very interesting games & lots of tips for mobile development.I highly recommend it!
Amazon Verified review Amazon
Geoffrey Hill Jan 28, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Packt publishing have been on a bit of a roll lately with the Unity books. I got this and the playmaker book for some holidays study type fun.This was by far the best.3 large detailed examples to work through, really impressed by the content detail and layout. There are some poorly explained game logic sections but since that's not the focus of the book I easily forgive it. (a couple of very clever blocks of code that do in 2 lines what I would have done in 20, my c# skills are pretty beginner)Highly recommended if you're interested in using unity to develop for android.Just make sure you have spent a little time with C# first. =)
Amazon Verified review Amazon
Thom Feb 04, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is not merely dry, instructive details but good 'hands-on' construction of some real-world games. Additionally, there are ample screenshots to help guide and verify that you are progressing correctly on each step.As an instructor of software programming I truly appreciate the very methodical and progressive approach this book takes. With each chapter you build, gradually, on information (and hands-on illustrations) from previous chapters.Although I have experience with Unity3D, I have never explored development for the Android platform. Additionally, there are aspects of the Unity3D platform that I was not aware prior to reading this book!This book contains very thorough and clear explanation of the specifics to Mobile (Touch, Tilt). No other books I have seen on this subject has given this much attention to that.After completing this book you will not only have a very strong knowledge and understanding of Unity3D development for the Android platform, but also the foundation of a several fun games on which to build and grow your expertise.
Amazon Verified review Amazon
Dimitris-Ilias Gkanatsios Jun 27, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Loved that book, great samples, some advanced stuff. Content applies to almost all mobile platforms. Highly recommended for novice to intermediate Unity users.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.