I have been working on a project and I want on pressing the key the first animation starts, then if I press the same key while the previous animation is being played, it should transmit to next animation and I want to add minimum 5 animations in that and I want to add exit time too while we change the animation.
@fafase @Mike 3 @Bunny83 @Eric5h5 @robertbu @aldonaletto @tanoshimi @whydoidoit @duck @clunk47
Put timers after each animations. Then if the button is pressed while the timer is active, play the next animation.
Or use this code…
public class AnimationCycler : MonoBehaviour
{
[SerializeField] private int currentAnimationIndex = 0;
private Animator animator;
private void Start()
{
var _animator = GetComponent<Animator>();
if (_animator != null)
{
animator = _animator;
}
}
private void Update()
{
if (animator != null)
{
if (Input.GetKeyDown(KeyCode.X))
{
if (currentAnimationIndex < 4)
{
currentAnimationIndex += 1;
}
else
{
currentAnimationIndex = 0;
}
}
animator.SetInt("Index", currentAnimationIndex);
}
}
}
And then create a state machine that looks like this…
thank u very much sir