Book Image

Unity 2D Game Development Cookbook

By : Claudio Scolastici
Book Image

Unity 2D Game Development Cookbook

By: Claudio Scolastici

Overview of this book

<p>Unity is a powerful game development engine that provides rich functionalities to create 2D and 3D games.</p> <p>Unity 2D Game Development Cookbook is a practical guide to creating games with Unity. The book aims to serve the purpose of exploring problematic concepts in Unity for 2D game development, offering over 50 recipes that are easy to understand and to implement, thanks to the step-by-step explanations and the custom assets provided. The practical recipes provided in the book show clearly and concisely how to do things right in Unity. By the end of this book, you'll be near "experts" when dealing with Unity. You will also understand how to resolve issues and be able to comfortably offer solutions for 2D game development.</p>
Table of Contents (15 chapters)
Unity 2D Game Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Coding the Boolean-based transitions


With the transition between Idle and Jump configured in the Animator window, we can script a piece of code to trigger it. With the following recipe, we show how simple it is to control animations through scripting with Unity.

Getting ready

As usual, we follow on from the last recipe. You just need to add a C# script in the Scripts folder of the project (as you learned in Chapter 2, Importing 3D Graphics) and name it Char_Animator.

How to do it...

  1. Access the Scripts folder in your Project panel and double-click on the newly created script to open it in Monodevelop, the default Unity script editor.

  2. Let's begin by creating an Animator type variable to store the reference to the character animator and add the following line at the top of the script:

    private Animator charAnimator;
  3. Get inside the Start() function; here we need to address the charAnimator variable we created to the actual animator that we will attach to the character. We do that by adding the following...