Flipping a sprite horizontally – using Animator State Chart and Transitions
In this recipe, we'll use (in a simple way) the Unity animation system to create two states corresponding to two animation clips, and a script that changes localScale according to which animation state is active. We'll use a second script, which will map the arrow keys press Horizontal
input axis values to a Parameter
in the state chart, and which will drive the transition from one state to the other.
While it may seem like a lot of work, compared to the previous recipe, such an approach illustrates how we can map from input events (such as key presses or touch inputs), to Parameters
and Triggers
in a State Chart
.
Getting ready
For this recipe, we have prepared the image you need in a folder named Sprites in folder 08_02
.
How to do it...
To flip an object horizontally using Animator State Chart
and Transitions
, follow these steps:
- Create a new Unity 2D project.
- Import the provided image:
EnemyBug.png
. - Drag an instance of...