Beginning 3D Game Development with : The World’s Most Widely Used Multi-platform

■ ■ ■ Sue Blackman

i

■ CONTENTS

Beginning 3D Game Development with Unity: The World’s Most Widely Used Multiplatform Game Engine Copyright © 2011 by Sue Blackman All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. LucasArts and the LucasArts logo are registered trademarks of Lucasfilm Ltd. © 1992-1998 Lucasfilm Entertainment Company Ltd. or Lucasfilm Ltd. & ® TM as indicated. All rights reserved. ISBN 978-1-4302-3422-7 ISBN 978-1-4302-3423-4 (eBook) Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. President and Publisher: Paul Manning Lead Editor: Michelle Lowman Technical Reviewer: Peter Laliberte and Robert Reed Editorial Board: Steve Anglin, Mark Beckner, Ewan Buckingham, Gary Cornell, Jonathan Gennick, Jonathan Hassell, Michelle Lowman, James MarkhamMatthew Moodie, Jeff Olson, Jeffrey Pepper, Frank Pohlmann, Douglas Pundick, Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh Coordinating Editor: Anita Castro Copy Editor: Mary Behr, Mary Ann Fugate, and Sharon Terdeman Compositor: Richard Ables Indexer: BIM Indexing & Proofreading Services Artist: SPi Global Cover Designer: Anna Ishchenko Distributed to the book trade worldwide by Springer Science+Business Media, LLC., 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail [email protected], or visit www.springeronline.com. For information on translations, please e-mail [email protected], or visit www.apress.com. Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Special Bulk Sales– eBook Licensing web page at www.apress.com/bulk-sales. The information in this book is distributed on an “as is” basis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work. The code for this book is available to readers at www.apress.com. You will need to answer questions pertaining to this book in order to successfully download the code.

ii

■ CONTENTS

For Phillip, who kept reminding me about how long I had been talking about writing this book

iii ■ CONTENTS

Contents at a Glance

■About the Author ...... xv ■About the Technical Reviewer...... xvi ■Acknowledgments...... xvii ■Introduction...... xviii ■Chapter 1: Exploring the Genre...... 1 ■Chapter 2: Unity UI Basics—Getting Started ...... 45 ■Chapter 3: Scripting: Getting Your Feet Wet ...... 93 ■Chapter 4: Terrain Generation: Creating a Test Environment ...... 121 ■Chapter 5: Navigation and Functionality ...... 181 ■Chapter 6: Cursor Control...... 251 ■Chapter 7: Action Objects...... 309 ■Chapter 8: Managing State...... 407 ■Chapter 9: Object Metadata...... 439 ■Chapter 10: Message Text ...... 453 ■Chapter 11: Inventory Logic ...... 505 ■Chapter 12: Managing the Inventory ...... 545 ■Chapter 13: Finishing the Basic Functionality...... 587 ■Chapter 14: Getting Down to Game...... 655 ■Chapter 15: A Maze and the Final Level ...... 753 ■Chapter 16: Menus and Levels ...... 821 ■Chapter 17: Beyond the Basics...... 907 ■Appendix A: SSE Shader Graphs...... 939 ■Appendix B: Key Codes...... 943 ■Appendix C: Final Sequence ...... 949 ■Index...... 951

iv ■ CONTENTS

Contents

■About the Author ...... xv ■About the Technical Reviewer...... xvi ■Acknowledgments...... xvii ■Introduction...... xviii ■Chapter 1: Exploring the Genre...... 1 Historical Reference ...... 1 Graphical Adventure...... 4 LucasArts Titles...... 6 Fast Forward to Real Time...... 6 What draws people to this genre?...... 7 Intriguing Locations and Entertaining Solutions...... 13 Defining a Style...... 14 Compartmentalizing Environments...... 17 Parallax ...... 18 Animation...... 20 Challenges, Tasks, and Puzzles ...... 20 What went wrong with the genre?...... 20 Modern Successes of the Genre...... 22 What basic human characteristics make for fun?...... 23 Why make your own?...... 25 Multiple Roles ...... 25 Two Logical Variations for Indies ...... 26 First Person...... 26 Character ...... 26 Common to Both ...... 27 Design Considerations for First Person ...... 28 Developing the Story and Challenges...... 29 New to Real Time vs. Pre-Render...... 31 Chapter Summary...... 43

v ■ CONTENTS

■Chapter 2: Unity UI Basics—Getting Started ...... 45 Installing Unity and Starting Up...... 45 Loading or Creating a New Project or Scene...... 45 The Layout...... 50 Scene Window ...... 52 Game Window ...... 52 Hierarchy View...... 53 Project View ...... 54 Inspector ...... 54 Toolbar ...... 55 Menus...... 57 File ...... 57 Edit...... 57 Assets ...... 58 GameObject...... 58 Component Menu...... 59 Terrain Menu...... 59 Window Menu ...... 59 Help Menu...... 59 Creating Simple Objects...... 59 Selecting and Focus ...... 65 Transforming objects ...... 66 Snaps...... 69 Vertex Snaps ...... 70 Scene Gizmo...... 71 Non-Snap Alignment...... 72 Lights...... 74 3D Objects ...... 83 Meshes...... 83 Sub-Objects of a Mesh...... 83 Mapping ...... 85 Materials...... 92 Summary ...... 92 ■Chapter 3: Scripting: Getting Your Feet Wet ...... 93 What is a Script? ...... 93 Components of a Script...... 94

vi ■ CONTENTS

Functions ...... 94 Variables ...... 103 Picking an Object in the Game...... 108 Counting Mouse Picks...... 114 Conditionals and State ...... 115 Deconstructing the Conditional...... 118 Order of Evaluation...... 119 Chapter Summary...... 119 ■Chapter 4: Terrain Generation: Creating a Test Environment ...... 121 Flythrough Scene Navigation ...... 126 Topography...... 126 Paint Texture ...... 131 Trees...... 135 Sky ...... 143 Back to the Trees ...... 147 Packages...... 148 Paint Details ...... 159 Creating Your Own Terrain Assets ...... 164 Export vs. Use Native Format...... 167 Terrain Settings...... 167 Shadows...... 169 Fog...... 176 Chapter Summary...... 178 ■Chapter 5: Navigation and Functionality ...... 181 Navigation ...... 181 Fun with Platforms...... 207 Collision Walls...... 220 Your First ...... 241 Summary...... 249 ■Chapter 6: Cursor Control...... 251 Cursor Visibility...... 251 Custom Cursors...... 254 GUI Layer ...... 255 Texture Importer ...... 257 Color Cues...... 268

vii ■ CONTENTS

Cursor Position...... 268 Managing a GUITexture Cursor ...... 270 Object-to-Object Communication...... 272 Mouse Over Cursor Changes ...... 275 Distance Check ...... 281 Quick Publish...... 285 Object Reaction to Mouse Over ...... 287 Making the New Functionality Optional...... 305 Preventing Mouse Over Functionality While Navigating...... 307 Chapter Summary...... 308 ■Chapter 7: Action Objects...... 309 Importing Assets...... 309 Importing ...... 311 FBX Importer...... 323 More Control over Individual Objects ...... 331 Individual Transforms ...... 336 Complex Hierarchies...... 337 Parenting...... 338 Setting up Materials ...... 341 The Keys...... 342 The Chest ...... 348 Flower ...... 352 Shadows...... 355 Static Objects...... 356 Colliders...... 361 Animation ...... 368 Accessing Store in Root ...... 371 Adding Sound F/X...... 375 Setting up a Two-State Animation...... 380 Using Unity’s Animation view...... 383 Changing Imported Animations...... 395 Triggering Another Object’s Animations...... 400 Limitations...... 404 Summary ...... 404

viii ■ CONTENTS

■Chapter 8: Managing State...... 407 Identifying the Possibilities ...... 408 Introducing the Plot...... 408 Walk-through ...... 409 Action Items ...... 411 Stunt Doubles...... 412 Developing a Flow Chart...... 412 Separating State Metadata Transition Action ...... 414 Defining Interaction and State...... 414 Visualizing State Transitions...... 415 State Diagram ...... 419 Evaluating the Results...... 422 Lookup Table ...... 423 Parsing a String...... 425 The Object Lookup Script ...... 427 Action Related Messages ...... 437 Chapter Summary...... 438 ■Chapter 9: Object Metadata...... 439 State-Related Metadata ...... 440 State of Being/Location...... 442 Visibility Type ...... 442 Game Notes...... 443 Current State ...... 444 Mouse Pick Revisited ...... 444 Adding Metadata ...... 448 Chapter Summary...... 452 ■Chapter 10: Message Text ...... 453 GUI Skin...... 453 OS Font Support...... 457 Text Visibility ...... 466 Using the Object Metadata ...... 471 Handling the Action ...... 475 Getting Real...... 481 Managing Audio ...... 482 Processing Animation ...... 484

ix ■ CONTENTS

Loading the Start-Up Values ...... 488 More on Fonts and Text ...... 492 Activating the Action Message...... 496 Dynamic Read Time ...... 500 A Final Refinement...... 502 Summary ...... 504 ■Chapter 11: Inventory Logic ...... 505 Layers...... 505 Converting the Cursor...... 510 A Few More Refinements...... 514 Inventory Screen ...... 516 Extending the Lookup Table ...... 526 Leaving Breadcrumbs ...... 529 Adding Inventory Icons...... 530 2D Object Handling...... 539 Chapter Summary...... 543 ■Chapter 12: Managing the Inventory ...... 545 Tags...... 555 Inventory Layout...... 558 Inventory Overflow ...... 560 Setting the Limits ...... 566 Inventory Grid Limits ...... 567 Arrow Limits...... 571 Adding and Removing Objects from Inventory ...... 573 Removing Objects from Inventory...... 574 Adding Objects to Inventory ...... 577 Combining Items ...... 578 Wrong Picks ...... 580 Summary ...... 584 ■Chapter 13: Finishing the Basic Functionality...... 587 Handling 3D Object Visibility ...... 587 Developing Non-Keyframed Fades...... 592 Side Effects of Visibility Changes...... 593 Dealing with Colliders ...... 595 Processing No-Match Cursors ...... 598

x ■ CONTENTS

Random Replies...... 599 Dropping Cursors in the 3D Scene ...... 605 Building the Visibility Function...... 610 Action Message Revisited...... 612 Back to Fades ...... 616 Object to Object Interaction...... 618 Positioning Objects in the Scene...... 625 Special Cases ...... 629 Extensible Code...... 630 Reply, No State Change...... 631 Activating the Treasure Chest Sequence ...... 632 Reading Material...... 643 Hiding the Message ...... 651 Chapter Summary...... 652 ■Chapter 14: Getting Down to Game...... 655 Drop Box...... 655 Reviving the Flower...... 664 Frustum Culling...... 670 Pouring the Elixir...... 672 Solving the Vial Visibility ...... 674 Making the Magic Happen ...... 675 Destroying the GameObjects...... 680 Activating the Prefab...... 682 Camera Focus...... 683 Camera Match Metadata...... 686 Scripting the Camera Match ...... 688 Importing the Final Assets...... 694 Bringing in the Structures...... 694 Materials and Lightmapping ...... 697 Underground ...... 703 Into the Temple ...... 708 Holograph Image...... 713 The Balcony...... 718 Getting the Topi Fruit ...... 721 The Elements ...... 732 The Waterfall...... 735 The Shrine’s Guardian...... 741

xi ■ CONTENTS

The Bouncer...... 746 Summary ...... 752 ■Chapter 15: A Maze and the Final Level ...... 753 Maze Geometry ...... 753 Managing the Maze...... 758 Drop Points...... 761 Checking for Traps...... 764 Confiscated Weapons...... 767 Playing the Odds...... 770 User Reset...... 770 Activating the Drawer ...... 772 Easter Egg...... 780 The Cavern Portal...... 782 The Final Level ...... 785 Tree Generator ...... 785 The Standing Stones ...... 788 The Prize ...... 790 A Touch of Wind ...... 791 The Final Terrain ...... 792 The Final Sequence...... 799 Environmental Effects ...... 805 Animation Events ...... 809 Add Some Sparkles...... 810 Multiple Topis...... 812 Load Level...... 818 Summary ...... 819 ■Chapter 16: Menus and Levels ...... 821 Menu Access: The Mini-Menu...... 821 Confirm Dialog ...... 825 Tracking Menu Mode ...... 828 The Main Menu ...... 830 The Settings Menu ...... 834 Player Settings...... 837 Filling in the Controls ...... 839 Color Selector...... 842 Finishing Audio...... 849 Sound FX...... 849

xii ■ CONTENTS

Ambient Sound...... 851 Music ...... 852 Voice or Dialog Volume ...... 855 Custom Skin for Menus ...... 856 Suspending Navigation and Scene Interaction Finishing Menus ...... 860 Real-Time Backgrounds...... 862 Start Menu/Level ...... 866 Managing the Backgrounds ...... 868 Changing Levels...... 873 Save/Restore ...... 874 Saving the Game Data...... 877 Loading the Saved Data ...... 881 Tidy Up ...... 885 Finally, Back to the Start ...... 889 Is It Done Yet? ...... 899 Final Tasks ...... 902 Publishing ...... 903 Publishing...... 904 Summary ...... 905 ■Chapter 17: Beyond the Basics...... 907 Additional Features ...... 907 HUD Score/Rating...... 907 Hints/Difficulty ...... 908 Multiple Saves...... 909 Physics and Projectiles ...... 910 Retaining Data...... 910 Additional Content...... 911 From First Person to Third Person...... 912 Characters...... 912 Cameras...... 913 Character Dialog ...... 914 Dialog Trees ...... 915 Character Alternatives ...... 919 Design Considerations for Mobile Platforms ...... 919 License, Hardware, and Setup...... 920 Scripting...... 921

xiii ■ CONTENTS

Navigation and Input ...... 922 Shaders and Textures ...... 923 Count ...... 924 Batching...... 925 Colliders ...... 927 Menus and GUI...... 927 Miscellaneous ...... 927 Design Doc ...... 928 The Story/Game in Its Briefest Form...... 928 The Story/Game in More Detail ...... 929 Who Is the Game For?...... 931 What is the Target Platform? ...... 931 Uniqueness and Marketability...... 931 Controls and Navigation...... 931 Game Mechanics...... 932 Assessment, Scoring, and Winning...... 933 Level Design...... 933 Visual Style...... 934 User Interface...... 934 Characters and Action Objects...... 934 Environmental and Non-Interactive Assets...... 935 Sound F/X...... 936 Music ...... 936 Voice ...... 936 Chapter Summary...... 936 ■Appendix A: SSE Shader Graphs...... 939 The SSE BetterLightmap Shader Graph...... 939 The SSE ReflectiveAlpha Shader Graph...... 940 The SSE ReflectiveCutout Shader Graph ...... 941 ■Appendix A: Key Codes...... 943 ■Appendix A: Final Sequence ...... 949 ■Index...... 951

xiv ■ CONTENTS

About the Author

■ Sue Blackman is a 3D artist and interactive applications author and instructor based in southern California. She has taught 3ds Max and game classes for artists for well over ten years in top-rated community colleges and private schools, such as the Art Institute of California, and has been lead 3D artist on games for Activision through one of their subsidiaries. She has worked in the industry for several years to help train Fortune 1000 companies, such as Boeing, Raytheon, and Northrop Grumman, to create serious games and training applications with game-based formats. She has been involved with the commercial development of real-time 3D engines for nearly ten years. She is an avid tutorial writer and has created both tutorials, as a contributing author, and artwork for various 3ds Max books over the years, as well as training manuals for 3D authoring applications for serious games. She has also written for ACM Siggraph on serious games, one of her favorite topics. You can visit her web site at www.3dadventurous.com.

xv

■ CONTENTS

About the Technical Reviewers

■ Peter Laliberte runs the web site burgzergarcade.com, which focuses on teaching game development with a strong emphasis on using Unity3d. He came over to Unity3d around two years ago after using Objective-C for iPhone development, and has never looked back. Besides using Unity3d, he is a skilled programmer in several languages, including C/C++, PHP, and Java. When he is not busy cooking up some crazy game mechanics, he enjoys spending time outdoors with his two-year-old son and wife.

■ Robert Reed is currently enrolled at Collins College in Phoenix, Arizona, studying game design, and he is set to graduate in March 2011. He quickly learned JavaScript and Unity3d in about a year and loved working on this book.

xvi ■ CONTENTS

Acknowledgments

Thanks go out to Gabriel Acosta and Jenny Wang, who helped brainstorm much of the game play for the book’s project. I owe special thanks to Jenny for the start menu design and stele idea.

Thanks also to Bryan Taylor and Sean McCurry of Binary Sonata Studios for the temple music and camera match code, and to Daniel Butler for providing the voice (in three different variations) of the temple guardian.

Thank you all for taking time out from your own game projects to contribute to mine. Your assets, ideas, and enthusiasms were much appreciated.

xvii ■ CONTENTS

Introduction

Why Write This Book Real time 3D games have been around for well over ten years now. We’ve played them, created assets in the style of our favorites, and maybe even “mod”ed a few of them. But until recently, the cost of licensing one of the premier game engines has ranged from several hundred thousand to several million dollars per title (!), relegating the dream of creating your own 3D game to an unattainable fantasy. Times have changed. 3D has become affordable not only in the movie industry, as seen by the number of titles featuring CG (computer graphics), but also in the game industry where we’ve seen a shift in casual games from 2D to a 3D format. With Unity’s bold move to offer a robustly featured free version of their engine, a radical change in the pricing models of the high-end engines has rocked the industry. The cost of the engine is no longer a barrier to taking your game from a nebulous idea to a working prototype and even on to a marketable product. Whether your interest is in casual games or you have more ambitious aims, if you have no previous scripting experience but are eager to bring your art assets and story to life, this may be just the book to get you underway. In today’s modern game engines, the heavy programming is handled by the engine itself, so the logic and game play can be scripted by those with more creativity than traditional programming knowledge. In this book, I will approach game creation and design decisions from a 3D artist’s view, taking the logic and scripting in small pieces, while introducing artists, budding game designers, and novice programmers to real-time game engine concepts at the same time. This book is written in a project-based format so you will not only end up with a playable game and scripting resources you can reuse for other games, but you will experience typical design decisions that need to be addressed throughout the process. You will create your game by starting with the basics and refining it as you add functionality; I will explain the logic behind certain choices and real-time game concepts as you go along. The project for this book is based on a first person point and click adventure game, complete with inventory, state management, load/save functionality, and a strong emphasis on the visual aspects of game creation. Even if you are more of a first person shooter-type game enthusiast, you will be able to see how including entertaining or interesting tasks and features can enhance your favorite genre. The aim of this project is to introduce you to a logical progression of design decisions and problem solving that will be of value well beyond the scope of the adventure game genre. It provides a framework and a methodology for creating and, more importantly, finishing your own game. You will be going beyond the basic Unity functionality and use of standard assets to investigate topics rarely covered in online tutorials or books. All of the necessary art assets to complete the project are provided.

Author’s Note In a recent game class, after working through a race game, a first person shooter, and a platform jumper, I decided that the last project would be a classic adventure game. Much to my surprise, the class got

xviii ■ INTRODUCTION

quite motivated with all of the design decisions and logic involved. As there were no existing tutorials at the time on this genre, we created the game from the ground up, borrowing scripts from the previous projects, creating several of our own, and drawing heavily on the knowledge base of the Unity community. This book grew out of that experience, both to fill a need and to share the adventure with others.

Classic Adventure Game For this project you will be creating a variation on the classic point and click adventure game. The adventure genre, of which there are many variations, is an ideal starting place for artists and others with little or no scripting experience. The story, art assets, and animation are major components of this type of game, and the slower pace allows more freedom from script optimization as split-second player reaction time is not required. One of the most enjoyable components of the adventure game is the collection and usage of an odd assortment of objects. Because of the importance of inventory and state management, several chapters are dedicated to their design and implementation. Neophyte Unity developers often ask how to implement these features in community forums, but they rarely receive answers due to the scope of the topic. By the end of this book, you will be armed with the scripts, concepts, and experience to be able to take the knowledge beyond this genre. Interactive adventure games are also ideal for indie developers, and they appeal to a broad range of players. Tell Tale Games’ Tales of Monkey Island was one of the top selling casual games of the year, proving once again their appeal, established by the original LucasArts series.

About the Unity Game Engine Unity is the perfect choice for small studios, indie developers, and those of us who have always wanted to make our own games. Its large user base (over 400,000 as of April 2011) and extremely active user community allows everyone from newbies to seasoned veterans to get answers and share information quickly. Unity provides an excellent entry point into game development, balancing features and functionality with price point. The free version of Unity allows people to experiment, learn, develop, and sell games before committing any of their hard-earned cash. Unity’s very affordable, feature-packed Pro version is royalty free, allowing people to make and sell games with the very low overhead essential to the casual games market. The market for multi-platform games—especially casual games for iPhone—is extremely popular at the moment, and Unity’s commitment to cross platform delivery is well proven. Originally a Mac-based authoring application that could publish to Mac and Windows, Unity unveiled its Windows version in the spring of 2009. As expected, it has opened up opportunities for PC-based developers and artists. Since that time, Unity has continued to add support for iPhone, Android, iPad, and and is developing support for and PS3. The free Unity Web Player has surpassed 35 million installations. Early adapters of the Unity engine tended to migrate from Flash and Director, making the scripting environment easily adoptable. While many Unity users have an ActionScript background in making Flash games, it is by no means a prerequisite. There is a lot of material for creating games in Unity, including first person shooters, racing games, platform jumpers, and the like. Even if your interest lies elsewhere, there are plenty of helpful tips and tricks to be gleaned from even the most unlikely sources. Don’t be afraid to take advantage of the resources available on the Unity web site (www.Unity3D.com), the

xix ■ INTRODUCTION

Unity forum (forum.unity3d.com), the wiki (www.unifycommunity.com/wiki), UnityAnswers (answers.unity3d.com), and numerous private party web sites devoted to the Unity engine. Unity documentation also contains a wealth of valuable information, but, as with any technology that has a unique vocabulary, it’s sometimes hard to find just what you’re looking for. Prefacing your query with Unity3D and searching the Internet is often the easiest way to find elusive concepts or functionality. You can make use of them via the Help menu, but it is often quicker to take advantage of the online version.

Will I have to learn to script? You don’t have to be a programmer to make your own game with Unity, but you will need to be able to understand enough of what the scripts do to know what can be tweaked to your advantage or decide if a particular script will suite your needs. Most game play needs to be scripted in Unity, but there are hundreds of scripts already available that can be readily reused. Unity ships with several of the most useful. More can be found by searching the forum, Wiki, or UnityAnswers. Many forum members will even write bits of script for less adept users. In the Collaboration section of the forum, you can even find scripters looking to trade for art assets. By the end of this book, you should know enough to be able to take advantage of the wealth of material available from the Unity community. Games, by their very definition, are about interaction; even with games that are largely controlled by physics, logic-driven cause and effect is what differentiates games from linear plot-driven passive media. Even the most “artist friendly” game engines need scripting to move beyond simple environmental walkthroughs. This book’s aim is to familiarize you with scripting a few lines at a time, while providing visual feedback as often as possible. The assumption is that you have not yet decided to learn to script but are happy enough to participate in its creation in a more passive manner.

Scripting is More About Logic Than Syntax While many people worry that learning a new language will be difficult and intimidating, think of it this way: most people under the age of 35 are quite fluent in texting, which is a valid subset of our native language. To a certain extent, it has its own vocabulary and syntax, and it is very similar to scripting languages in that it is more of a subset than an entirely new language. The difference mainly lies in the method used to acquire the “language.” In texting, as with our native language, one doesn’t set out to study and learn the language. Instead, one absorbs, experiments, and eventually becomes competent through repeated contact, trial and error, and a host of other passive means rather than rote memorization and stressful examination. This book, because it’s about the logic behind game design and creation, treats scripting as an immersive experience that is a sideline to the game development process. You are free to choose your own amount of involvement with the scripting. Whatever you choose, the main scripts developed in the book will enable you to create or expand upon the final output of the book, the game, with your own ideas and art assets. That being said, there are only a few important concepts and a handful of keywords you need to know in order to get an idea of what’s being done in a script. Fortunately, most scripters are quite good at including comments explaining what the code is doing, thus making complicated scripts much less daunting to investigate. Scripts developed in this book will be provided on a per-chapter basis and the logic behind them explained in the chapters, but I hope that you will display classic adventurer curiosity and take advantage of the scripting explanations to do some experimenting on your own.

xx ■ INTRODUCTION

What About Math? One of the most common things we hear people say in the 3D industry is, “If I’d known math was going to be so useful, I would have paid more attention in class.” Be that as it may, most artists and designers are not going to want to invest any time in brushing up on their math skills. Don’t worry! My primary goal is to help you create a game. Some of the functionality you will scavenge for your game is easy to use without even knowing how it works. Most of us are quite happy to drive cars without having extensive knowledge of the internal combustion engine. Don’t be afraid to treat scripting the same way!

Assumptions and Prerequisites This book assumes that you are at least somewhat familiar with 3D assets and 3D space, but it does have a short review of the concepts and plenty of tips and tricks throughout. It assumes that you will not have had much scripting experience (if any at all) but that you’ll be willing to work through it in order to bring your stories to life. It assumes that, as of yet, you have little or no experience with using the Unity game engine. It also assumes that you are fairly new to the game-making process but have a strong desire to create your own real-time 3D game. Additionally, this book assumes that if you want to explore genres other than classic point and click adventure games, you will work through the book with a goal of thinking about how to apply the various techniques to get results related to the other genre. In the casual game market, combining elements of adventure games, first person shooters, and other genres is not only acceptable but makes for some very entertaining results.

What This Book Doesn’t Cover This book is not about conventional game design; it is more of a precursor, getting you into the habit of analyzing needs and weighing choices. Not only is creating a massive design document intimidating when you are the one who will have to implement everything, but it is likely to be unrealistic until you are more familiar with the engine and your own capabilities. You’re going to build your game up a little bit at a time, prototyping ideas and functionality as you go along. This is not a book on how to become a programmer, still less on programming best practices. The scripting in this book is designed to ease a non-programmer into the process by providing instant visual feedback as often as possible. While there are usually several ways to attain the same goal, the scripting choices made in this book are the easiest to read and understand from an artist or designer’s point of view. In this book, scripting is presented in the way a native speaker learns his own language. He is surrounded by it, immersed in it, and allowed to tinker with it to slowly gain a basic working knowledge of it. Don’t worry about remembering it all. Some things you will use throughout the project and others you will be encouraged to take note of for future reference.

xxi ■ INTRODUCTION

Conventions Used in This Book 1. Instructions look like this.

■ Tips Follow this format.

Code looks like this.

Platform This book was written using Unity 3.x in a Windows 7 and a Windows XP environment. Differences for shortcut keys and operating system file storage with Unity on a Mac will be noted throughout the book.

xxii