Book Image

Getting Started with Unity

By : Patrick Felicia
Book Image

Getting Started with Unity

By: Patrick Felicia

Overview of this book

<p>Unity is a game development engine which is fully integrated with a complete set of intuitive tools and rapid workflows used to create interactive 3D content. Unity is best used for making great games that can deploy to numerous platforms.</p> <p>"Getting Started with Unity" guides you progressively through the necessary steps to create a survival game using Unity3D&rsquo;s built-in objects and components, JavaScript, animations with Mecanim, and some basic AI.</p> <p>In this book, you will be introduced to a wide range of the core features used for games developed with Unity3D, including the user interface and much more. Furthermore, you will also learn about essential aspects like transformations, scripting, navigation, and built-in controllers.</p> <p>Beginning with an introduction to the user interface, you will learn the necessary skills required to create a survival video game. Each section is a stepping-stone toward the completion of the final game. By the end of the book, you will have created an indoor level with enemies, AI, weapons, objects to collect, and all the logic to control the game.</p>
Table of Contents (13 chapters)
Getting Started with Unity
Credits
About the Author
About the Reviewer
www.packtpub.com
Preface
Index

Preface

Getting Started with Unity will get you up to speed with Unity3D's core features, using an easy step-by-step approach. Throughout this book, you will progressively develop your skills to create a survival video game.

From Unity3D's interface to finite state machines with Mecanim, you will learn all of the necessary features to create a great game, including built-in objects manipulation, collision detection, textures, scripting, audio, particle effects, pathfinding, and raycasting.

You will create an indoor environment, where the player can collect objects (including a gun, ammunitions, or health packs), shoot at enemies, open doors based on some conditions, and much more.

You will include animated zombies with different levels of intelligence that follow and attack the player based on a finite state machine and some AI techniques (for example, breadcrumbing).

You will also learn how to create a menu system for your game, manage and display the health levels of the character, and keep track of these factors across levels.

What this book covers

Chapter 1, Getting to know Unity3D, is a general introduction to Unity3D. In this chapter, we will look at Unity3D's interface and how to include assets to scenes, using both built-in objects and external files, such as sounds and textures. We will also become familiar with the most commonly used components in Unity3D.

Chapter 2, Creating a Maze with Built-in Objects, illustrates how to create a simple, (yet challenging) indoor environment using Unity3D's primitives and standard assets.

Chapter 3, Using Scripts to Interact with Objects, explains how to use scripting in Unity3D to create a user interface, handle user interaction, and display customized messages on the screen.

Chapter 4, Creating and Tracking Objects, explains how to add more interaction to our game with special effects, GUI elements, and a mini-map. We will also look at advanced techniques to handle cameras and camera views.

Chapter 5, Bringing Your Game to Life with AI and Animations, teaches you how to bring the game to life by animating objects and characters, and by giving NPCs some levels of artificial intelligence to challenge the player. We will also learn how to set up and manage a finite state machine with Mecanim to manage these characters.

Chapter 6, Finalizing and Optimizing Your Game, will introduce you to a technique called breadcrumbing to improve the NPCs' intelligence and pathfinding. You will also learn how to create menus for the different stages of the game, and how to navigate through them.

What you need for this book

To complete the projects in this book, you only need Unity 4.x (or a more recent version) that you can download from www.unity3d.com/download/.

All instructions on how to download and install Unity3D are provided in the first chapter.

Who this book is for

This book is for game developers who would like to learn how to use Unity3D and become familiar with its core features. This book is also suitable for intermediate users who would like to improve their skills. No prior knowledge of Unity3D is required.

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: "Create a new Boolean parameter called withinReach."

A block of code is set as follows:

public var walking:boolean = false;
public var anim:Animator;
public var  currentBaseState:AnimatorStateInfo;
public var walkForwardState:int = Animator.StringToHash("Base Layer.WalkForward");
public var idleState:int = Animator.StringToHash("Base Layer.Idle");
private var playerTransform:Transform;
private var hit:RaycastHit;

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

case:walkForwardState
  var zombies:GameObject [] = GameObject.FindGameObjectsWithTag("zombie");
  for (var zombie:GameObject in zombies)
  {
    if (Vector3.Distance(transform.position, zombie.transform.position) < 8.0f)
zombie.GetComponent(controlZombie).setWalking(true);
  }
  break;

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: "Click on the Animations tab, and then click on the label attack; this label will provide information on the attack clip."

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 via 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 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.

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/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 on our website, or added to any list of existing errata, under the Errata section of that title. 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 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.