Set MecAnim trigger once until state returns

729 Views Asked by At

I'm trying to play a single animation once on a character in Unity using MecAnim. I'm really not familiar with any of this, so I might have got the approach completely wrong.

The base layer contains a lot of walking stuff, but the animation I'm trying to trigger is on a seperate Right Arm layer with an empty Default state. There is a Wave trigger applied to the Default -> Wave transition, and a timed exit on the Wave -> Default one.

MecAnim - Right Arm Graph

I then have a script which (while debugging) fires when you press 'O' and causes the character to wave, once.

if (Input.GetKey(KeyCode.O))
{
    AnimatorStateInfo currentState = this.animator.GetCurrentAnimatorStateInfo(1);
    if (currentState.IsName("Right Arm.Default"))
    {
        Debug.Log("Waving triggered");
        this.animator.SetTrigger("Wave");
    }
}

The animation plays as expected, but the console shows that the IsName check is always passing as true, which makes me think I'm doing something wrong.

The in transition takes a fraction of a second to complete, then after that if the SetTrigger method is invoked again, the animation will play twice.

I'm looking for a simple way of ensure the trigger is only ever set when the state of this layer has fully returned to default.

0

There are 0 best solutions below