Learning 2D Game Development with Unity®: A Hands-On Guide to Game Creation

Book description

The Unity Engine Tutorial for Any Game Creator

¿

Unity is now the world’s #1 game engine, thanks to its affordability, continuous improvements, and amazing global community. With Unity, you can design, code, and author your game once, and then deploy it to multiple platforms, reaching huge audiences and earning maximum returns. Learning 2D Game Development with Unity® will help you master Unity and build powerful skills for success in today’s game industry. It also includes a bonus rundown of the new GUI tools introduced in Unity’s version 4.6 beta.

¿

With this indispensable guide, you’ll gain a solid, practical understanding of the Unity engine as you build a complete, 2D platform-style game, hands-on. The step-by-step project will get you started fast, whether you’re moving to Unity from other engines or are new to game development.

¿

This tutorial covers the entire development process, from initial concept, plans, and designs to the final steps of building and deploying your game. It illuminates Unity’s newly integrated 2D toolset, covering sprites, 2D physics, game scripts, audio, and animations. Throughout, it focuses on the simplest and lowest-cost approaches to game development, relying on free software and assets. Everything you’ll need is provided.

¿

Register your book at informit.com/title/9780321957726 to access assets, code listings, and video tutorials on the companion website.

¿

Learn How To

  • Set up your Unity development environment and navigate its tools

  • Create and import assets and packages you can add to your game

  • Set up game sprites and create atlas sheets using the new Unity 2D tools

  • Animate sprites using keyframes, animation controllers, and scripting

  • Build a 2D game world from beginning to end

  • Establish player control

  • Construct movements that “feel right”

  • Set up player physics and colliders

  • Create and apply classic gameplay systems

  • Implement hazards and tune difficulty

  • Apply audio and particle effects to the game

  • Create intuitive game menus and interface elements

  • Debug code and provide smooth error handling

  • Organize game resources and optimize game performance

  • Publish your game to the web for others to see and play

  • ¿

    Table of contents

    1. About This eBook
    2. Title Page
    3. Copyright Page
    4. Dedication Page
    5. Contents at a Glance
    6. Contents
    7. Preface
      1. Why Write This Book?
      2. Who Is This Book For?
      3. Why Did We Choose to Use Unity?
      4. What Will You Need?
      5. How Much Scripting Is Involved?
      6. How Is the Book Organized?
      7. Conventions Used in This Book
      8. Supplementary Materials
    8. Acknowledgments
    9. About the Authors
    10. Introduction
      1. Introduction to Unity
        1. Downloading and Installing Unity
      2. Project Wizard
        1. Open Project Tab
        2. Create New Project Tab
        3. Packages
      3. Setting Our Project
        1. Project Structure
        2. Folder Organization
        3. File Naming Conventions
    11. 1. Setting Up the Unity Development Environment
      1. Welcome Screen
      2. The Unity Interface
        1. Menus
        2. Toolbar
        3. Hierarchy
        4. Inspector
        5. Project Browser
        6. Scene View
        7. Game View
      3. Summary
      4. Exercises
    12. 2. Understanding Asset Creation
      1. File Formats
        1. 3D Formats
        2. 2D Formats
      2. Importing Our Assets
        1. Importing from Inside Unity
        2. Importing Premade Assets from the File Browser
        3. Creating New Assets
      3. Importing Packages
        1. Unity Packages
        2. Custom Packages
      4. GameObjects
        1. Our First GameObject
        2. Creating a GameObject
      5. Components
        1. Creating a Component
        2. Assign a Component
        3. Prefabs
      6. Summary
      7. Exercises
    13. 3. Creating 2D Sprites
      1. Working in 2D
        1. 2D Behaviors
        2. 2D Workspace
      2. Building Our Sprites
        1. Import Settings
        2. Pixels To Units
        3. Sprite Editor
      3. Sprite Packing
        1. Packing Tag
        2. Sprite Packer
        3. Additional Sprite Packing Resources
      4. Summary
      5. Exercises
    14. 4. Building the Game World
      1. Level Design 101
        1. Setting the Scene
        2. Creating a Roadmap
        3. Adding Details
      2. Getting around Our Scene
        1. Scene Gizmo
        2. Perspective versus Isometric
        3. Camera Controls
      3. Manipulating Objects in Unity
        1. Transform Tools
        2. Z-Depth
        3. Settings
      4. Our First Level
        1. Positioning GameObjects Manually
        2. Using the Snap Settings to Position GameObjects
        3. Using Grid Snapping to Position GameObjects
        4. Efficient Level Design
        5. Adding Sorting Elements
      5. Continuing On
      6. Summary
      7. Exercises
    15. 5. The Basics of Movement and Player Control
      1. Coding in Unity3D
        1. The Three Languages
        2. Choosing the “Right” Language
      2. Making the Player Go
        1. Different Ways of Handling Movement
        2. Creating and Hooking Up Our PlayerController
      3. Setting Up a Basic Follow-Cam
      4. Introducing the Input Manager
      5. Error Handling and Debugging
        1. Handling Exceptions
        2. Try-Catch-Finally—Gracefully Handling Exceptions
        3. Debug.Log() Is Your Friend
        4. Using Breakpoints to Halt Code Execution
      6. Summary
      7. Exercises
    16. 6. Adding Animations to Our Scene
      1. Some Rules for Animation
        1. Animation Principles
        2. 2D versus 3D Animation
        3. Transform versus Frame Animation
        4. Scripted Animations
        5. Imported Animations
      2. Creating Animations
        1. Animation Component
        2. Animation Clip
        3. Animation Window
        4. Animation Events
      3. Animation States
        1. Animator Controller
        2. Animator Component
        3. Animator Window
        4. Editing the Player Controller
      4. Working with the State Machine
        1. Transitions
        2. Any State
        3. Blend Trees
      5. Summary
      6. Exercises
    17. 7. Setting Up Player Physics and Colliders
      1. Understanding Physics
        1. Mass
        2. Gravity
        3. Force
      2. 2D versus 3D
        1. 6DoF
        2. Z-Depth
        3. Rotations
      3. Physics 2D Settings
        1. General Physics Settings
        2. Layer Collision Matrix
      4. Rigidbodies
      5. Colliders
        1. Circle Collider
        2. Box Collider
        3. Edge Collider
        4. Polygon Collider
      6. Physics Materials
      7. Constraints
      8. Summary
      9. Exercise
    18. 8. Creating and Applying Gameplay Systems
      1. Trigger Volumes in Unity
        1. Trigger2D Functions
        2. Adding Trigger Components to GameObjects
      2. Creating Checkpoints
        1. Scripting the Checkpoint Component
        2. Sizing and Placing Our Checkpoint Trigger
      3. Using Checkpoints with Respawn
        1. Preparing the Pit Trigger Volume
        2. Scripting the Pit Trigger Component
      4. Creating Collectibles
        1. Preparing the Floating Coin Prefabs for Collection
        2. Scripting the CoinPickup Component
        3. Preparing the Popped Coin Prefabs for Collection
        4. Preparing the Coin Box Prefabs
        5. Scripting the Coin Box Component
        6. Scripting the CoinSpawner Component
        7. Hooking It All Together
        8. A Touch of Polish
      5. Tracking the Player’s Stats
      6. Summary
      7. Exercises
    19. 9. Creating Hazards and Crafting Difficulty
      1. Creating Your First Enemy
        1. Preparing the Slime Enemy GameObject
        2. Inheritance and the EnemyController Component
        3. Scripting the Enemy Slime Component
        4. Adding Walls to the Level
        5. Handling Collision with Other Slimes
        6. Adding Animation to the Slime
      2. Dealing Damage
        1. Scripting Damage into the PlayerStats Component
        2. Creating the Damage Trigger
        3. Passing through the Player’s Space
        4. Adding Damage to the Pits
        5. Adding Temporary Immunity Post-Damage
        6. Visually Representing Immunity, the Classical Way
      3. Handling Player Death
      4. Expanding on Platforming
        1. Preparing the Moving Platform Prefab
        2. Scripting the Flight Points Component
      5. Creating Your Second Enemy
        1. Preparing the Fly Enemy GameObject
        2. Adding Animation to the Fly
        3. Scripting the FlyController Component
        4. Adjusting the FlightPoints Script
      6. Maintaining Your Enemy Arrangements
        1. Preparing the Spawn Trigger
        2. Scripting the Spawn Trigger Component
      7. A Few Words on Challenge
      8. Summary
      9. Exercises
    20. 10. Creating the Menus and Interface Elements
      1. UI Design
        1. Diegetic
        2. Non-diegetic
        3. Meta
        4. Spatial
      2. Unity Native GUI
        1. GUI Style
        2. GUI Skin
        3. GUI Controls
        4. Compound Controls
        5. GUI Class
        6. GUI Layouts
        7. GUI Text
        8. GUI Texture
      3. Creating a Splash Screen
      4. Title Screen
      5. Game Over Screen
      6. Game Win Screen
      7. HUD
        1. Creating the Visuals
        2. Creating the Scripts
      8. Summary
      9. Exercise
    21. 11. Applying Effects to the GameObjects
      1. Introducing the Shuriken Particle System
        1. Terms to Know
        2. Creating a Particle System
      2. Modules and Properties of a Particle System
        1. Base Particle System Properties
        2. Other Particle System Modules
        3. Particle System Curves
      3. Adding Particle Effects to the Game
        1. Creating a Particle Effect for Coin Boxes
        2. Hooking Up the Coin Box Particle Effect
        3. Creating a Particle Effect for Damage
        4. Calling the Damage Particle System from Code
        5. Having a Little Particle Fun
      4. Unity’s Audio System
        1. The Audio Source Component
        2. The Audio Listener Component
        3. The Audio Reverb Zone Component
      5. Adding Sound to the Player
        1. Adding Footsteps to the Walk Cycle
        2. Adding Sound to the Jump Event
        3. Adding Sound to the Damage Event
      6. Adding Sound to the Collectible System
        1. Applying Sound to the Coin Box
        2. Applying Sound to Coin Collection
      7. Applying Some Extra Polish
        1. Cleaning Up the Camera
        2. Cleaning Up Player Death
      8. Summary
      9. Exercises
    22. 12. Organization and Optimization
      1. Organizing Assets
        1. Organizing Our Prefabs
        2. Labels
        3. Hierarchy
      2. Organizing Scripts and Code
        1. Organizing the Script Files
        2. Organizing the Code
      3. Optimizations
        1. Prefabs
        2. Physics
        3. Draw Calls
        4. Triangle Count
        5. Batching
        6. Rendering Statistics Window
      4. Summary
      5. Exercises
    23. 13. Bringing It All Together
      1. Tying the Levels Together
        1. Preparing the Victory Trigger Prefab
        2. Creating the Victory Trigger Script
        3. Retrieving the Coin Value
      2. Hooking Up the Intro Screens
      3. Win or Lose: Getting Back into the Action
        1. Recovering from Game Over
        2. Starting Over from a Win
      4. Building and Deploying the Game
        1. Web Player’s Build Settings
        2. PC, Mac, and Linux Standalone Build Settings
        3. Cross-Platform Player Settings
        4. Web Player’s Player Settings
        5. The Right Settings for the Job
        6. Building the Game for the Web Player
        7. Deploying the Game to the Web
        8. Post-Deployment
      5. Moving Forward
        1. Polish Considerations
        2. Monetization
      6. Final Words
    24. 14. UGUI
      1. UGUI Components
      2. Creating Our Example Interface
        1. Canvas Component
        2. Rect Transform
        3. UI Rect Tool
        4. Adding the Mask
        5. The Event System and Event Triggers
      3. Summary
    25. Appendix: JavaScript Code Samples
      1. Player Scripts
      2. Collectible Scripts
      3. Enemy Scripts
      4. Game System Scripts
      5. GUI Scripts
      6. Hazard Scripts
      7. System Scripts
    26. Index
    27. Code Snippets

    Product information

    • Title: Learning 2D Game Development with Unity®: A Hands-On Guide to Game Creation
    • Author(s):
    • Release date: December 2014
    • Publisher(s): Addison-Wesley Professional
    • ISBN: 9780133523416