Learn Unity3d Programming with Unityscript Suvak Also Available: ONLINE
Total Page:16
File Type:pdf, Size:1020Kb
Learn Unity3D Programming with UnityScript TECHNOLOGy iN ACtiON™ earn Unity Programming with UnityScript is your step-by-step Also available: Lguide to learning to make your first Unity games using UnityScript. Learn You will move from point-and-click components to fully customized features. You need no prior programming knowledge or any experience with other design tools such as PhotoShop or Illustrator - Unity3D Learn you can start from scratch making Unity games with what you’ll learn Unity3D in this book. Through hands-on examples of common game patterns, you’ll learn and apply the basics of game logic and design. You will gradually become comfortable with UnityScript syntax, at each point having everything explained to you clearly and concisely. Many beginner Programming Programming programming books refer to documentation that is too technically abstract for a beginner to use - Learn Unity Programming with UnityScript will teach you how to read and utilize those resources to hone your skills, and rapidly increase your knowledge in Unity game development. with UnityScript You’ll learn about animation, sound, physics, how to handle user interaction and so much more. Janine Suvak has won awards for her game development and is ready to show you how to start your journey as a game developer. The Unity3D game engine is flexible, Unity’s JavaScript for Beginners cross-platform, and a great place to start your game development with adventure, and UnityScript was made for it - so get started game programming with this book today. UnityScript CREATE EXcITING UNITY3D GAMES WITH UNITYScRIPT Suvak ISBN 978-1-4302-6586-3 54499 Shelve in Macintosh/General User level: Beginning 9781430 265863 SOURCE CODE ONLINE www.apress.com Janine Suvak For your convenience Apress has placed some of the front matter material after the index. Please use the Bookmarks and Contents at a Glance links to access them. Contents at a Glance About the Author .............................................................................................................. xvii About the Technical Reviewer ........................................................................................... xix Acknowledgments ............................................................................................................. xxi Introduction ..................................................................................................................... xxiii ■■Chapter 1: Getting Started with Unity ................................................................................1 ■■Chapter 2: Game Programming 101 ................................................................................27 ■■Chapter 3: Making a Simple Scene ..................................................................................61 ■■Chapter 4: Using Scripts and the GameObject .................................................................85 ■■Chapter 5: Moving the GameObject ...............................................................................109 ■■Chapter 6: Starting with Coding Physics .......................................................................157 ■■Chapter 7: Using Advanced Physics Concepts ..............................................................187 ■■Chapter 8: Particle Emitters and Special Effects ...........................................................221 ■■Chapter 9: Game Design and Logic—The Blueprint ......................................................249 ■■Chapter 10: Putting the Pieces Together and Building Your Game ................................269 ■■Chapter 11: Enhancing The User Experience: GUI and Sound ........................................303 v vi Contents at a Glance ■■Chapter 12: Optimizing Your Game ................................................................................337 ■■Chapter 13: Where to Go from Here ...............................................................................363 Index .................................................................................................................................387 Introduction If you have the desire to create video games but have no experience with programming or game development, this is the book for you. Unity is a powerful game development ecosystem for creating 2D and 3D games. With its basic but still powerful free version, Unity has blasted away the barriers to learning game development. While the Unity editor is visual and intuitive in nature, you will have to learn to script in order to complete your game. Not to fear—all you need is a computer, an Internet connection, and motivation. This book is written for the complete beginner in both game development and programming. Scripting, programming, and coding are synonymous terms that all refer to the process of writing computer code to direct some portion of the game behavior. While it may seem a little daunting, as with any other endeavor you simply start at the beginning and learn one thing at a time. You can’t make a game without writing some code, but creating the code is only a part of the game development process. You’ll have just as much fun learning to find and use characters, animations, special effects, and other assets as you will writing code for directing their interaction within your game. Unity Technologies, the maker of Unity3D, provides excellent support documentation that most often includes working sample code. When I was a beginner developer, whether in mobile apps or video games, I found that almost all of the documentation was just about as clear and useful as if it were written in hieroglyphics—pretty much incomprehensible. I was stuck in a hole where I needed documentation on how to use the documentation! The purpose of this book is to bridge this initial gap—to give you a foundation in programming within the context of using Unity to make a simple game, while connecting what you are learning to the relevant information found in the documentation, and even to using some of the sample code. This book is meant as a launching pad: by the time you are through working on its examples, you should be able to confidently build on your newfound knowledge and skills with the many resources introduced to you throughout this book. With that in mind, read the chapters in order. After an introduction to the basics of programming concepts and to the Unity editor in the first few chapters, the subsequent projects will begin building upon each other from one chapter to the next. To get the most out of this book, follow along and complete the projects step by step from scratch. The best way to learn and (just as important) retain what you are learning is by doing. Besides, it’s fun and definitely more satisfying to do it yourself. xxiii xxiv Introduction The game development industry is in constant motion, and with over half of all game developers using Unity, from individuals to large studios, you can bet that Unity Technologies is constantly pushing the envelope to provide better tools and game engine performance. In particular, during the time this book was written, several radical changes were made affecting animations, particle systems, and better assets for rapid prototyping. Any changes affecting the instructions in this book from Unity or elsewhere will be noted in the Errata section of the book’s Apress web page, www.apress.com/9781430265863. Sometimes it is helpful to have the finished project as a reference. You will be able to find the source code and finished projects for the examples in this book under the Source Code/Downloads tab of its Apress web page. The best way to learn how to make games is by making games, so turn the page to get started! Chapter 1 Getting Started with Unity This is a great time to learn to develop games. Unity has emerged as one of the most popular game engines for game developers, and Unity Technologies continues to make dramatic changes to make Unity more accessible to indie developers. There are now more platforms to which Unity games can be ported (meaning it can be used on many devices), the Asset Store is available for centralized game resources, and Unity provides outstanding support that has expanded to include professional assessment and feedback for your game. There is even an entire new (at the time of writing) division that collaborates with developers and publishes games. Making games is an amazing experience and provides even more bragging rights than a high score or near-impossible headshot. Welcome to the fun! By “games” the folks behind Unity also recognize the expanding field of “serious games”— simulations and other immersive, interactive experiences developed using Unity3D for a rising number of different industries and uses. From NASA’s Mars exploration and CliniSpace’s virtual medical training environments to CrossPlatform DeSign’s animated crime scene reconstructions and virtual industrial trainers, serious games are appearing in new venues at a rapid rate. If serious game development is the direction in which you want to go, I believe that Unity is the best tool for it and this book is the best place to get started. This book assumes you have a computer and that you are familiar enough with using an Internet browser to download files—and that is all. If you have an interest in game development but no prior experience in Unity, programming, or digital art/content creation, you are in the right place. If you have some background in one or the other, you’ll find this book helpful for introducing you to Unity, programming,