Flipping a sprite horizontally – using Animator State chart and transitions
In this recipe, we’ll use the Unity animation system to create two states corresponding to two animation clips.
Unity Animator Controllers manage a State Machine to control how and when an animated GameObject should change. At any point in time, a GameObject with an Animator Controller component is either in one state or transitioning between states.
We’ll have one script class that changes localScale
according to which animation state is active. There will also be a second script class, which will map the arrow keys to the Horizontal input axis values as a parameter in the State Machine, which will drive the transition from one state to the other.
While this 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 Machine.