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

Working with float parameters


In the following recipe, we will show you how to use a float type to switch between clips based on a value that changes continuously, such as the character speed.

Let's assume we have an animation loop for the walking state of the character and another for running. As the character speed increases, it switches between the two states. How can we achieve that? Check out the following recipe to know.

Getting ready

As usual, we follow on from the previous recipe. Have the FBX files named Char@Walk and Char@Run imported and available in the project panel and the Animator window open in the editor.

How to do it...

  1. Go to the Project panel and find the Walk and Run clips of your character. Drag them from the Project panel into the Animator window.

  2. Right-click on the Walk animation and make a transition to Run and another back from Run to Walk.

  3. Create a new parameter, this time a float variable, and name it fSpeed. The following screenshot shows the result you should have so...