Book Image

Unity Game Development Essentials

By : Will Goldstone
Book Image

Unity Game Development Essentials

By: Will Goldstone

Overview of this book

Game engines are central to the video games we know and love. From the artwork to the mathematics that underpin the frames onscreen, the engine calls the shots. Aside from offering one of the leading 3D game engines, Unity also provides a superlative development tool ñ a tool that can produce professional standard games for Mac, PC, and the Unity Web Player. This book is a complete exercise in game development covering environments, physics, sound, particles, and much more, to get you up and working with Unity quickly. Taking a practical approach, this book will introduce you to the concepts of developing 3D games before getting to grips with development in Unity itself. From creating 3D worlds to scripting and creating simple game elements you will learn everything you'll need to get started with game development for the PC, Mac, and Web. This book is designed to cover a set of easy to follow examples, which culminate in the production of a First Person 3D game, complete with an interactive island environment. By introducing common concepts of game and 3D production, you'll explore Unity to make a character interact with the game world, and build puzzles for the player to solve, in order to complete the game. At the end of the book, you will have a fully working 3D game and all the skills required to extend the game further, giving your end-user, the player, the best experience possible. Soon you will be creating your own 3D games with ease!
Table of Contents (17 chapters)
Unity Game Development Essentials
Credits
About the Author
About the Reviewers
Preface
Index

Preface

Unity is a 3D game authoring tool for Mac and PC. Game engines are the nuts and bolts that sit behind the scenes of every video game. From the artwork right down to the mathematics that decide every frame on screen, the "engine" makes the decisions. Starting out with rendering — the method of displaying graphics on screen, and integrating a control method and a set of rules for the game to follow — the engine is what a developer builds to "house" the game. Modern 3D game engines are a deluge of meticulously written code, and as such, once used for their intended purpose (which is the production of a game they are made for), these engines are often sold, modified, and reused. An obvious example of this is the Epic Games Unreal Engine. Originally developed in the late 90s for Unreal — a PC First Person Shooter the engine has gone on to see massive success in its more recent incarnations, being licensed by other developers for literally hundreds of commercial games and simulations.

Due to the level of complexity and cost of such commercial game engines, the game development industry is a difficult area of interest for potential fresh talent to break into, without studying programming languages such as C++ extensively. Modern console and computer games are built around C++ as it is currently the most efficient language in terms of computational speed, and as such, the structure and commands of commercial games engines require thousands upon thousands of such lines of code to function. This code is delivered in Unity with the help of just-in-time compilation (known as JIT), using the open source C++ library Mono. By using JIT compilation, engines such as Unity can take advantage of high-speed compilation, whereby the code you will write for Unity is compiled to Mono just before it is executed. This is crucial for games that must execute code at specific moments during runtime. In addition to the Mono library, Unity also takes advantage of other software libraries in its functionality, such as Nvidia's PhysX physics engine, OpenGL, and DirectX for 3D rendering and OpenAL for audio. All these libraries are built into the application, so you will not need to worry about learning how to use them individually. So, simply sit back and enjoy them working for you seamlessly within Unity.

The developers of engines also build tools with which to command the functional coding they have created. For example, the creation of an outdoor terrain is held in a set of instructions which define its shape (or topography), visual appearance, and even how it responds to deformation in game. But this set of instructions would be inefficient as a part of the game engine were it not attached to a visual tool to control the aforementioned properties. This is where a Graphical User Interface (GUI) comes in. Game engine developers will often build an interface of tools to aid their team in manipulating parts of the engine in order to save time in the development process and make the engine accessible to potential buyers, post production. This is also true of Unity, as it has a very strong community of users that share their tools in the form of plugins for the package. Visit the Unify community wiki at http://www.unifycommunity.com/wiki for more information.

For many new potential developers, the steep learning curve required to pick up programming languages such as C++, or the engines that utilize it, is simply too great a task to attempt. Without completing degree-level studies in programming or computer animation, it is difficult for many enthusiasts to get started in learning the concepts, methods, and design principles involved in game production. Unity Technologies is one such company that has set out to rectify this. Starting with their own game engine in 2001, the Danish-based game development company endeavoured to strip down their complex game development tools and make a simple, user-driven package that anyone could pick up and begin experimenting with. The team resolved to keep the source code that drives the engine behind the scenes, instead providing a complete GUI (Graphical User Interface) that allows the user to control the powerful engine source code without ever having to create parts of it themselves. This factor has made Unity highly popular with new developers, and is likely one of the key reasons you're reading this book. By establishing logical concepts and categorizing common methods involved in game production, Unity puts the power of its engine into the user's hands, allowing maximum results with minimal effort, thereby encouraging experimentation with the most crucial factor of all — gameplay.

Having appealed to many games developers, Unity has filled a gap in the games development market that few others can fully claim to cater to. Having the ability to produce professional standard games, publish 3D to both Mac and PC, as well as having its own Web Player, Unity is one of the fastest growing game engines in its sector. The engine also has its own Nintendo Wii and Apple iPhone developing versions, meaning that once you have mastered the basics, a pipeline to not only home computer, but also to console and mobile development lies ahead of you.

The fast pace of the entertainment and marketing industries requires a quick turnaround of gaming media. Also, many companies are now looking to packages such as Unity to enable their creatives to produce better products with the greatest of ease. With 2009 seeing the release of Unity version 2.5, and its first steps onto PC format, its usage looks set to skyrocket. But what is Unity? How does it work? What can it do? And most importantly, how can it get you get started on the path to 3D game development in just a few weeks?

What this book covers

This book is designed to cover a set of easy-to-follow examples, which culminate in the production of a First-Person-viewed 3D game, complete with an interactive island environment. By introducing common concepts of game and 3D production, we'll explore the use of Unity to make a player character interact with the game world, and build puzzles for the player to solve in order to complete the game.

Here's a quick chapter-by-chapter overview of what will be covered:

Chapter 1—Welcome to the Third Dimension

This chapter covers the key concepts we'll need to understand and complete the exercise in this book. It takes a brief look at 3D concepts and the processes used by Unity to create games.

Chapter 2—Environments

Our game world is but an empty void! We'll kick off with this chapter by taking a look at the various ways to incorporate terrains, externally produced 3D models, and other Unity engine features such as sound and lighting to get your game environment up and running.

Chapter 3—Player Characters

Every game needs a hero, right? In this chapter, we'll be taking a look at every element that goes into making the first-person player character from input controls to cameras and colliders. Once you've learnt what goes into making him, you'll introduce the player character to your island and take a stroll around.

Chapter 4—Interactions

Games are all about interacting with a virtual world, so where would our character be without some in-game actions? In this chapter, I'll introduce you to collision detection and ray casting. We'll look at how we can combine these techniques with scripting and animation to transform our static building into one that responds to our player.

Chapter 5—Prefabs, Collection, and HUD

Giving your player a sense of achievement in your game is essential. To help with this, you'll need to remind them of actions they've taken so far in the game, and give them something to aim for. In this fifth chapter, we will construct what is often referred to as a Heads Up Display (HUD) with text and graphical displays that change dynamically as the user plays.

Having created a simple HUD, you'll create a short object-collection game, which will allow the player character to pick up batteries in order to gain access to the building on the island.

Chapter 6—Instantiation and Rigidbodies

Almost every game scenario that you can imagine will involve creating or "spawning" objects in your environment. Known in programming terms as Instantiation, the creation of objects during the game's runtime is a crucial concept for every beginner developer to get to grips with.

Having created our collection game and building interaction in previous chapters, we'll be building upon the interactivity in our game by creating a basic target game, which will involve throwing objects at targets to unlock a part of our environment. This will not only teach you about instantiation, but also the crucial concept of using rigid body physics objects in your games.

Chapter 7—Particle Systems

What's a 3D game these days without some fancy graphic effects to wow the player? In this chapter, you'll be creating a log fire to keep our player warm — using two particle systems, one for flames and the other for smoke.

Using a Particle System, we'll look at how we can mimic the behavior of fire and utilize images for each particle to add realism; we'll finish by disabling the fire, giving the player something to aim for — getting it lit to keep warm!

Chapter 8—Menu Design

Creating a professional, easy-to-navigate menu is a crucial part of making an enjoyable game product. What user is going to want to play your game if he or she can't even find the Start button? In this chapter, we look at the various ways of creating menus and other user interfaces for the player to interact with.

You will create menus using both GUI textures and the GUI class in order to create scalable interfaces that can be deployed on the desktop or the Web.

Chapter 9—Finishing Touches

In game production, especially in Unity, you will reach a point at which you have just created some piece of interaction in your game that you're so pleased with, you want to add that extra polish to make it really stand out to the player.

In this chapter we'll take a look at further uses of sound, lighting effects, trail rendering, and other dynamic effects that are easy to implement, and make the difference between a simple working game and a polished final product.

Chapter 10—Building and sharing

In this chapter, we will look at how we can export your game for the Web and as a standalone project. We'll look at various different settings you will need to consider when you are preparing your finished product for your audience, such as graphical quality, control input, and more.

Chapter 11—Testing and further study

In this chapter, we will discuss the ways in which you should move on from this book, and how you can gather information from test users to improve your game. This will help you prepare your project to be tested by a wider audience to get feedback and make even better games!

What you need for this book

  • An installed copy of the Unity software — a trial version is available from Unity3D.com

  • Internet connection in order to download supplied 3D models and other assets, available from PacktPub.com

  • An available 3D modelling package, although this is not essential. All materials used are provided as per above. If you are new to modelling, you may wish to download one of a few free applications that work well with Unity, such as Blender from Blender.org.

Who this book is for

Having worked with Unity for the past few years as a tutor, I've found the main complaint that its users encounter is not with the software itself, but rather that there is a lack of introductory material for new users coming from a non-programming based background.

In the existing climate, this is, of course, rare; but with a tool such as Unity allowing such ease of production as it does, the importance of such a tutorial guide has become ever more pressing.

If you're a designer or animator who wishes to make their first steps into game development, or if you've simply spent many hours seated in front of video games, with ideas bubbling away in the back of your mind, Unity and this book could be your ideal starting point. I will assume no prior knowledge of game production and start completely from scratch, inviting you to simply bring with you a passion for making great games.

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: "We can include other contexts through the use of the include directive."

A block of code will be set as follows:

if(collisionInfo.gameObject.name == "matchbox"){
Destroy(collisionInfo.gameObject);
haveMatches=true;
audio.PlayOneShot(batteryCollect);

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 our text like this: "clicking the Next button moves you to the next screen."

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 drop an email to , and mention the book title in the subject of your message.

If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or email .

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 necessary assets for the book

Visit http://www.packtpub.com/files/code/8181_Code.zip to directly download the asset packages you will need to use to complete this book.

The package also contains example code for the programming parts of the book.

Errata

Although we have taken every care to ensure the accuracy of our contents, mistakes do happen. If you find a mistake in one of our books — maybe a mistake in text or 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 to 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 let us know link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata added to any list of existing errata. 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 web site 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.