O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Getting Started with Unity 5.x 2D Game Development

Book Description

Build a tower defense game and earn delectable C# treats by baking cupcakes and fighting fearsome sweet-toothed pandas

About This Book

  • Build a complete and exciting 2D Tower Defense game from scratch.
  • Understand and learn to perform each phase of the game development pipeline
  • Homework and exercises to improve your skills and take them to the next level

Who This Book Is For

If you are looking forward to get started with 2D game development, either if you are a newcomer to this world, or you came from 3D games or other game engines, this book is for you. Although there are many references to other resources throughout the book, it is assumed that you have a general understanding of C# and its syntax and structure.

What You Will Learn

  • Import and set up assets for 2D game development
  • Design and implement dynamic and responsive User Interfaces
  • Create and handle complex animation systems
  • Unlock all the potentiality of the physics engine
  • Implement Artificial Intelligence algorithms to give intelligence to your NPCs
  • Script gameplay and overall bring your ideas to life

In Detail

Want to get started in the world of 2D game development with Unity? This book will take your hand and guide you through this amazing journey to let you know exactly what you need to build the games you want to build, without sacrificing quality. You will build a solid understanding of Unity 5.x, by focusing with the embedded tools to develop 2D games. In learning about these, along with accurate explanations and practical examples, you will design, develop, learn how to market and publish a delectable Tower Defense game about cupcakes versus pandas.

Each chapter in this book is structured to give you a full understanding on a specific aspect of the workflow pipeline. Each of these aspects are essential for developing games in Unity. In a step-by-step approach, you will learn about each of the following phases: Game Design, Asset Importing, Scripting, User Interfaces, Animations, Physics, Artificial Intelligence, Gameplay Programming, Polishing and Improving, Marketing, Publishing and much more.

This book provides you with exercises and homework at the end of each chapter so that you can level up your skills as a Unity game developer. In addition, each of these parts are centered on a common point of discussion with other learners just like you. Therefore, by sharing your ideas with other people you will not only develop your skills but you will also build a network.

Style and approach

This is a fun step-by-step approach in the whole pipeline of 2D game development in Unity, which is explained in a conversational and easy-to-follow style. Each topic is explained sequentially, allowing you to experience both basics and advanced features of Unity. By doing this, the book is able to provide you with a solid grasp on each of the topics. In this way, by engaging with the book's content, exploring the additional references to further readings and completing the homework sections, you are able to challenge yourself and apply what you know in a variety of ways. Once you have finished reading this book, you will be well on your way to developing games from start to finish!

Table of Contents

  1. Getting Started with Unity 5.x 2D Game Development
    1. Getting Started with Unity 5.x 2D Game Development
    2. Credits
    3. About the Author
    4. Acknowledgment
    5. About the Reviewer
    6. www.PacktPub.com
      1. Why subscribe?
    7. Customer Feedback
    8. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Downloading the color images of this book
        3. Errata
        4. Piracy
        5. Questions
    9. 1. A Flat World in Unity
      1. Learning game development
      2. Tower defense games
      3. Designing our game
      4. Getting ready
      5. Remembering the past to build the future
      6. Organizing the project
      7. A 2D world
      8. Sprites
        1. Sprite Renderer
        2. Importing new friends
        3. The Sprite Editor
          1. Manual mode
          2. Automatic mode
          3. Polygonal mode
          4. Sprite Editor for UI-9-slice scaling
        4. Preparing the assets
      9. Scenes as levels
        1. Setting proportions
      10. There is more about the Unity interface
      11. Homework
      12. Summary
    10. 2. Baking Cupcake Towers
      1. 2D objects
      2. Parenting game objects
      3. Difference between world coordinates and local coordinates
      4. Ordering the different layers with Z-Buffering
      5. Unfolding the map
      6. Layers and tags
      7. Prefabs
      8. The game view
      9. Math background
      10. Scripting in Unity
        1. Creating new scripts
        2. Basics about scripts
          1. Variables
          2. Attributes
          3. Functions
        4. Execution order
      11. Making sprinkles
        1. The projectile class
          1. Scripting the projectile mother class
        2. Tons of sprinkles through Prefabs
      12. Baking cupcakes towers
        1. What a cupcake tower does
        2. Scripting the cupcake tower
          1. Shooting to the pandas
          2. Upgrading the cupcake tower, making it even tastier
        3. A pre-baked cupcake tower through Prefabs
      13. More about coding in Unity
        1. Static variables
        2. Inheritance
        3. Random numbers in Unity
      14. Homework
      15. Summary
    11. 3. Communicating with the Player – the User Interface
      1. Getting ready
      2. Designing the user interface
      3. Programming the user interface
      4. User interface system
        1. Canvas
          1. Screen space – Overlay
          2. Screen space – Camera
          3. World space
        2. Draw order of UI elements
        3. Visual components
          1. The Image component
          2. The Text component
        4. Basic transformations
          1. The Rect Tool
          2. The Rect Transform
        5. Layout components
          1. Fitters
          2. Layout groups
          3. The layout element component
        6. Interaction components
          1. The selectable base class
            1. Interactable option
            2. Transition options
            3. Navigation options
          2. Button
          3. Toggle and Toggle Group
          4. Slider
          5. Scrollbar
          6. Dropdown
          7. Input Field
          8. Scroll Rect
        7. More about UI rendering
          1. The canvas renderer
          2. More visual components
          3. UI effect components
          4. UI and lights
          5. The canvas components
          6. Canvas group
        8. Event system
      5. Scripting user interfaces
      6. Designing the interface for our game
      7. Preparing the scene for the UI
      8. Creating a health bar
        1. Creating and placing the health bar
        2. Scripting the health bar
      9. Implementing the sugar meter
        1. Creating and place
        2. Scripting the sugar meter
      10. More about UI scripting – handlers
      11. What about all the rest?
      12. Homework
      13. Summary
    12. 4. No Longer Alone – Sweet-Toothed Pandas Strike
      1. Getting ready
      2. Animations
        1. A historical overview
        2. Animations in video games
        3. Workflow for animations
        4. Animations clips and the Animator component
          1. Creating Animation clips with a controller
          2. The Animator component
          3. Creating the other animation clips
        5. The Animator
          1. The Animator window
          2. The Animator state machine
          3. The Animator states
            1. Special states
          4. The animator parameters
          5. The animator transitions
          6. Transition settings
          7. Transition graph
          8. Transition conditions
          9. Testing transitions
        6. The panda's Animation State Machine
          1. Testing the panda's Animation State Machine
        7. Scripting Animations
        8. State machine behaviours
          1. The destroy behaviour
          2. The panda script
      3. More about Animations
        1. Avatars
          1. Sub-state machines
          2. The hierarchical location menu
        2. Layers in the Animator
        3. Blending trees
        4. Animator Override Controller
          1. Culling Mode in the Animator component
          2. Root motion
          3. Inverse Kinematic
        5. Animator component information box
          1. Legacy animation
      4. Get animated!!
      5. Homework
      6. Summary
    13. 5. The Secret Ingredient Is a Dash of Physics
      1. Getting ready
      2. Physics in video games
      3. Physics – basics
        1. World coordinates and local coordinates
        2. Velocity
        3. Mass
          1. Centre of mass
        4. Kinematics
        5. Dynamics
        6. Force and torque
        7. Collisions
        8. Rigid body
        9. Friction – linear and angular drag
      4. The Unity Physics engine
        1. Understanding Physics in Unity
        2. Physics settings in Unity
      5. Physics components
      6. Rigidbodies
        1. How a Rigidbody 2D works
        2. Body types
        3. Rigidbody properties
        4. Dealing with rigidbodies
      7. Colliders
        1. Dealing with colliders
      8. Joints
        1. Main properties of Joints
          1. The other rigidbody
          2. Breaking joints
        2. Specific joints
          1. Distance Joint 2D
          2. Fixed Joint 2D
          3. Friction Joint 2D
          4. Hinge Joint 2D
          5. Relative Joint 2D
          6. Slider Joint 2D
          7. Spring Joint 2D
          8. Target Joint 2D
          9. Wheel Joint 2D
      9. Effectors
        1. Constant Force 2D
        2. Area Effector 2D
        3. Buoyancy Effector 2D
        4. Point Effector 2D
        5. Platform Effector 2D
        6. Surface Effector 2D
      10. Physics Material 2D
      11. Dealing with physics in Unity
      12. Other things about Physics
        1. The Simulate setting on rigidbodies
        2. Physics Raycaster 2D component
        3. The other Physics settings
          1. Gizmos for colliders
      13. Physics for our game
        1. Set up Pandas as a rigidbodies
        2. Set up projectiles as rigidbodies
        3. Detect sprinkles
      14. Homework
      15. Summary
    14. 6. Through a Sea of Sprinkles – Navigation in Artificial Intelligence
      1. Getting ready
      2. Introduction to artificial intelligence
      3. The importance of artificial intelligence in video games
      4. Navigation
        1. Aspects of navigation
        2. Pathfinding and its techniques
      5. Waypoints for enemies
      6. Getting the waypoint coordinates
      7. Implementing waypoints – the first/static way
        1. Implementing waypoints in the Game Manager
        2. Moving along the designed path – static
      8. Implementing waypoints – the second/dynamic way
        1. Implementing waypoints as separate entities
        2. Moving along the designed path – dynamic
      9. More about artificial intelligence in games
        1. Other techniques for navigation at the pathfinding level
        2. Navigation at the level of steering behaviours
        3. Navigation at the level of pathfinding/decision making – belief-driven pathfinding
        4. Beyond navigation
      10. Homework
      11. Summary
    15. 7. Trading Cupcakes and the Ultimate Battle for the Cake – Gameplay Programming
      1. Getting ready
      2. What does gameplay programming mean?
      3. Planning what is left to implement for our game
      4. Trading cupcake towers
        1. The trading parent class
        2. Modifying the CupcakeTowerScript
        3. Buying cupcake towers
        4. Selling cupcake towers
        5. Upgrading cupcakes towers
        6. Adding the trading options to the user interface
      5. Placing the towers
        1. Sketching the idea of how it works
        2. Allowed areas
        3. Scripting the placement script
      6. Selecting the towers
      7. The Game Manager
        1. Game over conditions
          1. Game over feedback
          2. The GameOver function
        2. Keeping track of the game's progress
      8. Panda invasion – spawning Pandas
        1. What is a coroutine?
        2. Sketching the idea of how it works
        3. Setting up the spawning system
        4. Managing waves
        5. The single wave
      9. The main menu
        1. Designing the main menu
        2. Creating the main menu in another scene
        3. Loading scenes through scripts
      10. Techniques we learnt in this chapter
      11. Homework
      12. Summary
    16. 8. What Is beyond the Cake?
      1. Enhancing and improving your game
        1. Improving cupcake towers
          1. Shooting policies
          2. Special sprinkles
          3. Aging and pricing model
        2. Improving the user interface
        3. Improving levels
          1. Multilevel
          2. Large maps
          3. Many paths
          4. Many Pandas
          5. Multiphase bosses
          6. A better spawning system
          7. Switching difficulty at runtime
      2. Training and extending your Unity skills to become a better game developer
        1. Making things easier for other team members
        2. Exposing events
        3. Sprinkles pooling
        4. Saving your data
        5. Debugging
          1. Remote Logs
          2. Cleaning the release version
        6. More about communication between scripts
        7. Documenting the code
        8. Protecting your game
        9. Building for more than one platform
          1. Input/output devices
          2. Virtual reality in Unity
        10. Balancing the game
        11. Extending the Unity editor
        12. Multiplayer and networking
        13. Practice makes perfect
      3. Improving the atmosphere of the game
        1. Visuals
          1. Color schemes
            1. Homework
          2. Lighting
            1. Lights in Unity
            2. Homework
          3. Environment
            1. Homework
          4. Special effects
            1. Particle systems
            2. Post processing
            3. Other visual effects
        2. Audio
          1. Music
          2. Sound effects
          3. Eliciting emotions
          4. Homework
          5. Audio in Unity
          6. External audio systems
      4. Teamwork
        1. It is not just about you, it is about working in a team
          1. Sharing a common vision
          2. Managing expectations
          3. Collaboration and communication are key
          4. Ways to communicate
        2. Version control
        3. Make a GDD and stick to it
        4. Keeping it tidy with project management tools
          1. Slack
          2. HacknPlan
          3. Drive
          4. Dropbox
          5. Trello
          6. Redbooth
          7. GitHub
          8. BitBucket
          9. Calendar
          10. Pinterest
          11. Hootsuite
      5. Polishing your game
        1. Processing the power
          1. Checking the build size
          2. Texture optimitation
          3. Stats and profiling
          4. Other optimization tips
        2. Playtesting
          1. Why are you even playtesting?
            1. Exercise
          2. Whom do you need to playtest?
            1. The solo test run
            2. Making it a social occasion
            3. Putting it within boundaries
            4. Reaching out to family and friends
            5. Those who are strangers
            6. Those who you want to play your game
          3. When
          4. Where
          5. What
            1. A little goes a long way
          6. How
        3. Methods of playtesting
          1. Observe
          2. Question and explain
          3. Reflect and follow up
      6. Creating your online presence
        1. Do your research
        2. Conducting an audit
        3. Engaging with your audience
          1. Rewarding engagement
        4. Marketing on social media
          1. Blog about it
          2. Twitter
            1. Exercise
          3. Instagram
          4. Facebook
          5. MailChimp
      7. Getting ready to publish
        1. Crowdfunding campaigns
        2. Building in Unity
        3. Clearing the air
        4. Accepting terms and conditions
      8. Localization
      9. Ethical considerations
      10. Summary
      11. Final notes and goodbye