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
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Unity 4.x Game Development by Example: Beginner's Guide

You're reading from   Unity 4.x Game Development by Example: Beginner's Guide A seat-of-your-pants manual for building fun, groovy little games quickly with Unity 4.x

Arrow left icon
Product type Paperback
Published in Dec 2013
Publisher Packt
ISBN-13 9781849695268
Length 572 pages
Edition 3rd Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Ryan Henson Creighton Ryan Henson Creighton
Author Profile Icon Ryan Henson Creighton
Ryan Henson Creighton
Arrow right icon
View More author details
Toc

Table of Contents (22) Chapters Close

Unity 4.x Game Development by Example Beginner's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. That's One Fancy Hammer! FREE CHAPTER 2. Let's Start with the Sky 3. Game #1 – Ticker Taker 4. Code Comfort 5. Game #2 – Robot Repair 6. Game #2 – Robot Repair Part 2 7. Don't Be a Clock Blocker 8. Hearty Har Har 9. Game #3 – The Break-Up 10. Game #3 – The Break-Up Part 2 11. Game #4 – Shoot the Moon 12. Game #5 – Kisses 'n' Hugs 13. AI Programming and World Domination 14. Action! Appendix Index

Preface

A word about the third edition

As I sit here in my luxurious velvet smoking jacket, taking a long draw on a pipe, and admiring the various stuffed hunting trophies around the room in an attitude of quiet contemplation, it dawns on me that I don't smoke or advocate sport-hunting, and that I have no idea what I'm doing in this room. The jacket, however, is quite nice. I think I'll keep it.

It's wonderful to see that this book, one of the very first instructional guides about Unity 3D on the market, has withstood both the test of time, and Unity Technologies' relentless release schedule. Owing to the rapid pace of technology, many things have changed in a few short years. C# has largely overtaken UnityScript as a preferred language; to that end, all of the code in the book has been supplemented with a C# translation, including notes on how to perform that translation yourself for past and future projects.

In the time since the first edition, computers have increasingly become our evil, dominating overlords. With that in mind, the third edition includes two bonus chapters that teach you how to build a two-player game, and then how to program the computer to act as the merciless second player who never loses. That chapter also contains information on how to make the computer player lose, which I present as secret codified data to be used by the resistance movement during the inevitable machine uprising. Stay ever vigilant!

Your future as a game developer

"Game Developer" has rapidly replaced "firetruck" as the number one thing that kids want to be when they grow up. Gone are the days when aspiring developers needed a university education, a stack of punch cards, and a room-sized computer to program a simple game. With digital distribution and the availability of inexpensive (or free) game development tools like Unity 3D, the democratization of game development is well underway.

But just as becoming a firetruck is fraught with peril, so too is game development. Too often, aspiring developers underestimate the sheer enormity of the multidisciplinary task ahead of them. They bite off far more than they can chew, and eventually drift away from their game development dreams to become lawyers or dental hygienists. It's tragic. This book bridges the gap between "I wanna make games!" and "I just made a bunch of games!" by focusing on small, simple projects that you can complete before you reach the bottom of a bag of corn chips.

What this book covers

Chapter 1, That's One Fancy Hammer!, introduces you to Unity 3D—an amazing game engine and game authoring tool that enables you to create games and deploy them to a number of different devices. You'll play a number of browser-based Unity 3D games to get a sense of what the engine can handle, from a massively-multiplayer online game all the way down to a simple kart racer. You'll download and install your own copy of Unity 3D, and mess around with one of the demos that ships with the product.

Chapter 2, Let's Start with the Sky, explores the difference between a game's skin and its mechanic. Using examples from video game history, including Worms, Mario Tennis, and Scorched Earth, we'll uncover the small, singular piece of joy upon which more complicated and impressive games are based. By concentrating on the building blocks of video games, we'll learn how to distil an unwieldy behemoth of a game concept down to a manageable starter project.

Chapter 3, Game #1 – Ticker Taker, puts you in the pilot seat of your first Unity 3D game project. We'll explore the Unity environment and learn how to create and place primitives, add Components like Physic Materials and rigidbodies, and make a ball bounce on a paddle using Unity's built-in physics engine without ever breaking a sweat.

Chapter 4, Code Comfort, continues the keep-up game project by gently introducing scripting. Just by writing a few simple, thoroughly-explained lines of code, you can make the paddle follow the mouse around the screen to add some interactivity to the game. This chapter includes a crash course in game scripting that will renew your excitement for programming where high school computer classes may have failed you.

Chapter 5, Game #2 – Robot Repair, introduces an often-overlooked aspect of game development—"front-of-house" User Interface design—the buttons, logos, screens, dials, bars, and sliders that sit in front of your game—is a complete discipline unto itself. Unity 3D includes a very meaty Graphical User Interface system that allows you to create controls and fiddly bits to usher your players through your game. We'll explore this system, and start building a complete two-dimensional game with it! By the end of this chapter, you'll be halfway to completing Robot Repair, a colorful matching game with a twist.

Chapter 6, Game #2 – Robot Repair Part 2, picks up where the last chapter left off. We'll add interactivity to our GUI-based game, and add important tools to our game development tool belt, including drawing random numbers and limiting player control. When you're finished with this chapter, you'll have a completely playable game using only the Unity GUI system, and you'll have enough initial knowledge to explore the system yourself to create new control schemes for your games.

Chapter 7, Don't Be a Clock Blocker, is a standalone chapter that shows you how to build three different game clocks—a number-based clock, a depleting bar clock, and a cool pie wedge clock, all of which use the same underlying code. You can then add one of these clocks to any of the game projects in this book, or reuse the code in a game of your own.

Chapter 8, Hearty Har Har, revisits the keep-up game from earlier chapters and replaces the simple primitives with 3D models. You'll learn how to create materials and apply them to models that you import from external art packages. You'll also learn how to detect collisions between game objects, and how to print score results to the screen. By the end of this chapter, you'll be well on your way to building Ticker Taker—a game where you bounce a still-beating human heart on a hospital dinner tray in a mad dash for the transplant ward!

Chapter 9, Game #3 – The Break-Up, is a wild ride through Unity's built-in particle system that enables you to create effects like smoke, fire, water, explosions, and magic. We'll learn how to add sparks and explosions to a 3D bomb model, and how to use scripting to play and stop animations on a 3D character. You'll need to know this stuff to complete The Break-Up—a catch game that has your character grabbing falling beer steins and dodging explosives tossed out the window by his jilted girlfriend.

Chapter 10, Game #3 – The Break-Up Part 2, completes The Break-Up game from the previous chapter. You'll learn how to reuse scripts on multiple different game objects, and how to build Prefabs, which enable you to modify a whole army of objects with a single click. You'll also learn to add sound effects to your games for a much more engaging experience.

Chapter 11, Game #4 – Shoot the Moon, fulfills the promise of Chapter 2, Let's Start with the Sky, by taking you through a re-skin exercise on The Break-Up. By swapping out a few models, changing the background, and adding a shooting mechanic, you'll turn a game about catching beer steins on terra firma into an action-packed space shooter! In this chapter, you'll learn how to set up a two-camera composite shot, how to use code to animate game objects, and how to re-jig your code to save time and effort.

Chapter 12, Game #5 – Kisses 'n' Hugs, teaches you to build a two-player 3D Tic Tac Toe game entirely within the Unity 3D game authoring tool. You'll learn about writing return values for your custom functions, and using 3D objects to build an essentially 2D game. This simple strategy game forms the basis for the following chapter.

Chapter 13, AI Programming and World Domination, steps you through the process of developing an artificial intelligence program, enabling your computer to win at Tic Tac Toe. From there, you'll modify the terrifyingly perfect AI algorithm so that it randomly makes "mistakes", and gives humankind a slim chance at Tic Tac Toe survival.

Chapter 14, Action!, takes you triumphantly back to Ticker Taker for the coup de grace—a bouncing camera rig built with Unity's built-in animation system that flies through a model of a hospital interior. By using the two-camera composite from The Break-Up, you'll create the illusion that the player is actually running through the hospital bouncing a heart on a tin tray. The chapter ends with a refresher on bundling your project and deploying it to the Web so that your millions of adoring fans (including your grandma) can finally experience your masterpiece.

Appendix is an essentially vestigial component of the colon, which can be surgically removed if it gives you any trouble.

What you need for this book

You'll need to be in possession of a sturdy hat, a desk chair equipped with a seatbelt, and an array of delicious snack foods that won't get these pages all cheesy (if you're reading the e-book version, you're all set). Early chapters walk you through downloading and installing Unity 3D (http://unity3d.com/unity/download/). A list of resources and links to additional software can be found in the Appendix.

Who this book is for

If you've ever wanted to develop games, but have never felt "smart" enough to deal with complex programming, this book is for you. It's also a great kick start for developers coming from other tools like Flash, Unreal Engine, and Game Maker Pro.

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 are shown as follows: "The audio.PlayOneShot command is perfect for collision sound effects."

A block of code is set as follows:

for(var i:int=0; i<totalRobots; i++)
{
  var aRobotParts:List.<String> = new List.<String>();

  aRobotParts.Add("Head");
  aRobotParts.Add("Arm");
  aRobotParts.Add("Leg");
}

When we wish to draw indicate that a line of code needs to be added or edited, the relevant lines or items are set in bold:

function Awake() 
{
  startTime = Time.time + 5.0;
}

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: "When you click on the Apply button, Unity creates its set of raster images based on the font that you're importing".

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 through 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 color images of this book

We also provide you 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/5268OT_ColoredImages.pdf

Downloading the example code

You can download the example code files for all Packt books 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. Each project in the book is intended to be built from the "ground up", beginning with an new project file. The downloadable .unitypackage files for this book contain the assets (sounds, images, and models) you need to build the projects. You may also download completed, working versions of each project for your reference, though these are not intended to be your "first stop" – they're more like the answer sheet at the back of a text book.

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/support, 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.

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.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image