Learning 2D Game Development with Unity

 Learning 2D Game Development with Unity?

Addison-Wesley Learning Series

Visit learningseries for a complete list of available publications.

The Addison-Wesley Learning Series is a collection of hands-on programming guides that help you quickly learn a new technology or language so you can apply what you've learned right away. Each title comes with sample code for the application or applications built in the text. This code is fully annotated and can be reused in your own projects with no strings attached. Many chapters end with a series of exercises to encourage you to reexamine what you have just learned, and to tweak or adjust the code as a way of learning. Titles in this series take a simple approach: they get you going right away and leave you with the ability to walk off and build your own application and apply the language or technology to whatever you are working on.

Learning 2D Game Development with Unity?

A Hands-On Guide to Game Creation

Matthew Johnson James A. Henley

Upper Saddle River, NJ ? Boston ? Indianapolis ? San Francisco New York ? Toronto ? Montreal ? London ? Munich ? Paris ? Madrid

Capetown ? Sydney ? Tokyo ? Singapore ? Mexico City

Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and the publisher was aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals.

The authors and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein.

For information about buying this title in bulk quantities, or for special sales opportunities (which may include electronic versions; custom cover designs; and content particular to your business, training goals, marketing focus, or branding interests), please contact our corporate sales department at corpsales@ or (800) 382-3419.

For government sales inquiries, please contact governmentsales@.

For questions about sales outside the United States, please contact international@.

Visit us on the Web: aw

Library of Congress Cataloging-in-Publication Data

Johnson, Matthew (Computer programmer) Learning 2D game development with Unity : a hands-on guide to game creation / Matthew Johnson, James A. Henley. pages cm Includes index. ISBN 978-0-321-95772-6 (pbk. : alk. paper)--ISBN 0-321-95772-5 (pbk. : alk. paper) 1. Computer games--Programming. 2. Unity (electronic resource) I. Henley, James A. II. Title. QA76.76.C672J64 2015 794.8'1526--dc23

2014037406

Copyright ? 2015 Pearson Education, Inc.

All rights reserved. Printed in the United States of America. This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. To obtain permission to use material from this work, please submit a written request to Pearson Education, Inc., Permissions Department, One Lake Street, Upper Saddle River, New Jersey 07458, or you may fax your request to (201) 236-3290.

Unity, Unity Free, Unity Pro, and the Unity Web Player are registered trademarks of Unity Technologies.

Adobe?, Flash?, and Photoshop? are registered trademarks or trademarks of Adobe Systems Incorporated in the United States and/or other countries. THIS PRODUCT IS NOT ENDORSED OR SPONSORED BY ADOBE SYSTEMS INCORPORATED, PUBLISHER OF Adobe? Flash? and Photoshop?.

The Kenney logo and the Made with Kenney Logo belong to Kenney.nl, Netherlands, used with permission.

Mac? is a trademark of Apple Inc., registered in the U.S. and other countries.

Linux? is the registered trademark of Linus Torvalds in the U.S. and other countries.

DirectX, Direct3D, and Visual Studio are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries.

ISBN-13: 978-0-321-95772-6 ISBN-10: 0-321-95772-5 Text printed in the United States on recycled paper at RR Donnelley in Crawfordsville, Indiana. First printing, December 2014

Editor-in-Chief Mark L. Taub

Executive Editor Laura Lewin

Development Editor Songlin Qiu

Managing Editor John Fuller

Senior Production Editor Kesel Wilson

Copy Editor Barbara Wood

Indexer Jack Lewis

Proofreader Melissa Panagos

Technical Reviewers Reshat Hasankolli, II Sheetanshu Sinha

Editorial Assistant Olivia Basegio

Cover Designer Chuti Prasertsith

Compositor Shepherd, Inc.

v

First and foremost, a big thanks to my friends and family for supporting me throughout this process. You pushed me

to start this book and then begged me to finish it!

To my late father, who taught me to inspire and entertain others with my talent and

wild imagination: I am forever your biggest fan.

Last, to the love of my life and best friend, Jessica: without you this book would have been just

more dust in the wind of my ideas. Thank you for all of your guidance and wisdom, and for believing that I could accomplish this. I love you always and forever.

--Matthew Johnson

For my wonderful wife, who brought me tea whenever I locked myself in my office to write and tolerated being temporarily widowed by this book.

--James A. Henley v

This page intentionally left blank

Contents at a Glance

vii

Contents at a Glance

Preface xix Acknowledgments xxv About the Authors xxvii

Introduction 1 1 Setting Up the Unity Development Environment 9 2 Understanding Asset Creation 27 3 Creating 2D Sprites 41 4 Building the Game World 53 5 The Basics of Movement and Player Control 71 6 Adding Animations to Our Scene 95 7 Setting Up Player Physics and Colliders 119 8 Creating and Applying Gameplay Systems 135 9 Creating Hazards and Crafting Difficulty 159 10 Creating the Menus and Interface Elements 193 11 Applying Effects to the GameObjects 215 12 Organization and Optimization 247 13 Bringing It All Together 269 14 UGUI 291 Appendix: JavaScript Code Samples 301

Index 323

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download