Unity Game Development Blueprints Explore the various enticing features of Unity and learn how to develop awesome games John P. Doran BIRMINGHAM - MUMBAI Unity Game Development Blueprints Copyright © 2014 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: November 2014 Production reference: 1041114 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-78355-365-5 www.packtpub.com Credits Author Project Coordinator John P. Doran Kranti Berde Reviewers Proofreaders James King Simran Bhogal Gary Riches Lucy Rowland Adam Single Jonathan Todd Jacquelyn Soh Indexers Kerrie Woollhouse Hemangini Bari Tejal Soni Commissioning Editor Akram Hussain Production Coordinator Aparna Bhagat Acquisition Editor Harsha Bharwani Cover Work Aparna Bhagat Content Development Editor Ruchita Bhansali Technical Editors Shiny Poojary Sebastian Rodrigues Copy Editors Roshni Banerjee Sarang Chari Adithi Shetty About the Author John P. Doran is a technical game designer who has been creating games for over 10 years. He has worked on an assortment of games in teams with members ranging from just himself to over 70, in student, mod, and professional projects. He previously worked at LucasArts on Star Wars: 1313 as a game design intern; the only junior designer on a team of seniors. He was also the lead instructor of DigiPen-Ubisoft Campus Game Programming Program, instructing graduate-level students in an intensive, advanced-level game programming curriculum. John is currently a technical designer in DigiPen's Research and Development department. In addition to that, he also tutors and assists students on various subjects while giving lectures on game development, including C++, Unreal, Flash, Unity, and more. In addition to this title, he has authored Getting Started with UDK and Mastering UDK Game Development, and co-authored UDK iOS Game Development Beginner's Guide; he is also the author of the UDK Game Development video—all available from Packt Publishing. I want to thank my brother, Chris, and my wife, Hannah, for being supportive and patient with me as I spent my free time and weekends away from them to work on this book. On that same note, as always, I also want to thank Samir Abou Samra and Elie Hosry for their support and encouragement while working on this book as well as the rest of the DigiPen Singapore staff. Last but not least, I'd love to thank my family as well as my parents, Joseph and Sandra, who took me seriously when I told them I wanted to make games. About the Reviewers Gary Riches is a senior software engineer and long-standing member of the iOS developer community. He has a keen interest in emerging technologies and is currently exploring what's possible with virtual reality. Having worked as a software engineer for 16 years, he has had the opportunity to present his work worldwide at technology events, such as CES, Electronica, and Apps World. He is the author of Ouya Unity Game Development, Packt Publishing and co-author of You can make an APP, Future Publishing. When not building apps for clients, he also creates games and educational experiences for his own company, Bouncing Ball Games. The titles so far include Aztec Antics, Amazed, and Nursery Rhymes: Volumes 1, 2, and 3. Adam Single is a husband, father, professional developer, indie developer, lover of music, and gamer. He's the coder for 7bit Hero; a programmer on the tech team at Real Serious Games in Brisbane, Australia; cofounder, programmer, and codesigner at Sly Budgie; and co-organizer of the Game Technology Brisbane meetup. Since entering the professional game development industry in 2011, Adam has worked on numerous mobile games, including the Android hit Photon and a pre-installed game for specific Disney Japan handsets. He's been the programmer on a team that created a huge, interactive display at Queensland University of Technology's amazing multitouch screen installation, The Cube, as a part of Australia's first Digital Writing Residency and worked on a team at Real Serious Games creating large-scale, interactive simulations for the mining and construction industries. All of this has been done using the Unity game engine. Adam has a passion for the unique and engaging possibilities inherent in modern technology. When he's not working on exciting new game mechanics for Sly Budgie, he's experimenting with "homemade VR" using mobile phone technology and pushing the exciting ideas behind 7bit Hero's live music/multiplayer game interaction down whichever fascinating path it may lead. Jacquelyn Soh is a game developer who has been creating games for over 7 years. She is proficient in multiple aspects of game development, including programming, game designing, producing, and even art development. She is skilled in multiple languages and engines, including C, C++, C#, JavaScript, ActionScript, Python, HTML, CSS, Unity, Scirra Construct, Microsoft XNA, and several others. Jacquelyn began her programming career in Flash, working on an online virtual world. Unsatisfied with her knowledge, she joined DigiPen Institute of Technology and graduated with a Bachelor's degree in Computer Science and Game Design with a Mathematics Minor. Jacquelyn has since worked on a variety of games including virtual worlds, indie games, serious games, and various professional projects. Some game titles she has worked on include Tiny Dice Dungeon, Wiglington and Wenks, and Lord of the Guardians. She is currently working as a software engineer and an indie developer. She can be found online at www.jacquelynsoh.com and can be contacted at [email protected]. Kerrie Woollhouse is a very creative and artistic individual with 7 years of experience in game development, web development, art, and photography. She has also recently enjoyed being a technical reviewer for Packt Publishing Unity books, including Learning Unity 2D Game Development by Example. Kerrie continues to follow her passions with the highest ambitions and looks forward to expanding on current and future projects. I would like to say a special thank you to my wife for all her love and continuous support. www.PacktPub.com Support files, eBooks, discount offers, and more You might want to visit www.PacktPub.com for support files and downloads related to your book. Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details. At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks. TM http://PacktLib.PacktPub.com Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can access, read and search across Packt's entire library of books. Why subscribe? • Fully searchable across every book published by Packt • Copy and paste, print and bookmark content • On demand and accessible via web browser Free access for Packt account holders If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books. Simply use your login credentials for immediate access. Table of Contents Preface 1 Chapter 1: 2D Twin-stick Shooter 7 Project overview 7 Your objectives 7 Prerequisites 8 Setting up the project 9 Creating our scene 12 Scripting 101 16 Implementing player movement 17 Shooting behavior 26 Creating enemies 31 Adding GameController to spawn enemy waves 34 Particle systems for enemy explosion 39 Adding in sound effects/music 42 Adding in points, score, and wave numbers 44 Publishing the game 48 Summary 50 Challenges 50 Chapter 2: Creating GUIs 51 Project overview 51 Your objectives 52 Prerequisites 52 Project setup 52 The anatomy of a GUI control 56 ControlType 56 Position 56 Content 57