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

Setting up an Animator


Double-click on Packt_Animator from the Project panel to open the Animator panel in Unity. If you messed up a little with it, delete anything except the default Idle node.

How to do it...

  1. Create three new empty states by right-clicking anywhere in the Animator window, then select Create State and Empty, as shown in the following screenshot. Name them runRight, runLeft, Idle and Jump.

  2. Add the run animation clip to both runRight and runLeft states, as shown in the following screenshot:

  3. Lastly, add the jump_pose clip to the Jump state. Here's a screenshot, just in case:

  4. Now we can take care of the transitions. First of all we need two variables: a float called fSpeed to check whether we should trigger the left or the right sided running animation, and a Boolean called bJump for jumping. You should remember how to do this. The following screenshot shows what you are searching for:

  5. Create a new transition from Idle to runRight, and in the Inspector panel, set the condition to...