Book Image

Unity Game Development Scripting

By : Kyle D'Aoust
Book Image

Unity Game Development Scripting

By: Kyle D'Aoust

Overview of this book

Table of Contents (17 chapters)
Unity Game Development Scripting
About the Author
About the Reviewers


This book will cover many helpful topics that you can utilize when you create your own games. As a game developer and scripter, you'll end up writing a lot of code that you would not want to write again; this book will help to solve that. You will learn how to make gameplay elements modular so that they can be used again in other projects as well. This book will take what you might already know about gameplay scripting in Unity to the next level.

What this book covers

Chapter 1, Interactive Input, gives an in-depth look at how to create controls for both the Xbox 360 Controller and mouse/keyboard inputs. Along with creating those inputs, you'll also create customizable control profiles that the player can use to play your game the way they want to.

Chapter 2, GUI Time, will help you create both 2D and 3D GUI elements. This covers health bars, player data, hovering 3D health bars, 3D damage reports, enemy names, and so on.

Chapter 3, Expandable Item Classes, will teach you how to create in-game item classes for self, melee, and projectile items. Then, you'll create a classification system for these items to determine what they do.

Chapter 4, Inventory, will teach you a way to create an inventory system for your game. In this system, there'll be common inventory elements created such as adding items, removing items, and creating quick-select items. Finally, you'll also create a way to show the inventory on the GUI.

Chapter 5, Enemy and Friendly AIs, will demonstrate how to create a dynamic AI. It will cover what a finite state machine is and also what a behavior tree is. This AI system will handle behaviors, actions, animations, pathfinding, and also a waypoint system.

Chapter 6, Keeping Score, covers how to create, track, and save stats for the player. You'll also create a system for achievements for those stats as well.

Chapter 7, Creating Save and Load Systems, covers how to create systems to save and load from a flat file as well as an XML file. Then, you'll take these systems and implement them on a checkpoint-based save system and an anywhere/anytime saving system.

Chapter 8, Aural Integration, covers the creation of systems that will handle background music, atmospheric sounds, and sound effects. These systems are a playlist system, a randomized system, and an event-driven system.

Chapter 9, Game Settings, covers how to create customizable configurations for audio and video settings. You'll create the ability to save and load these settings by using PlayerPrefs.

Chapter 10, Putting It All Together, will put almost everything you've learned from the previous chapters into a small game. By taking elements from the previous chapters, you'll create a short First Person Action RPG.

What you need for this book

For this book, all that you'll need is Unity3D to write all of the scripts needed and Notepad++ to create XML files. While you may be able to create XML files in other programs, I use Notepad++ because it's easy to use and is a nice program to have as a programmer.

Who this book is for

This book can be used by someone who already has some programming or scripting knowledge and wants to get into game development using Unity3D. If you've already been using Unity3D for some time, this book may be of use to you as well as it has a theme to create modular gameplay elements.


In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "The reset function will use our SetDefaultValues() function as well as reset a couple of our other variables."

A block of code is set as follows:

void Reset()
  ShowPopup = false;
  PreviousKey = KeyCode.None;

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Open up the Axes dropdown by clicking on the arrow next to it."


Warnings or important notes appear in a box like this.


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 disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in 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 at

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 from your account at for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit and register to have the files e-mailed directly to you.


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 could 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, 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.

To view the previously submitted errata, go to and enter the name of the book in the search field. The required information will appear under the Errata section.


Piracy of copyrighted 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.


If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.