animator: goes to another state that i not expect

This is my state machine

State Change,Conditions,Input Control
Idle → Walk,IsMove == true,MouseDown anywhere in game
Walk → Idle,IsMove == false,MouseUp anywhere in game
Walk → Attack,Trigger “Attack”,MouseUp on enermies
Attack → Idle,None,None

When MouseUp on enermies, it occurs two things:
Trigger “Attack” and set “IsMove” to false.
I’m sure that trigger “Attack” happens before set “IsMove” to false.
But state goes to Walk → Idle, not Walk → Attack.
So Attack Animation not played.
Can anyone tell me why? thank you!

Hi.

Edit your question and remove the code formatting for your normal text please.

This seems to be a logic problem.

MouseUp anywhere is a bigger condition than MouseUp on enemies.

if(Input.GetKeyUp(KeyCode.Mouse0) //<= Clicking anywhere happens ALWAYS...
{
    walk->Idle //...so this also happens always, regardless of anything that comes after it.

    if(MouseOverEnemy) // happens only when a enemy is marked
    {
        walk->Attack //so this will happen because the anywhere loop is happening anyways.
    }
}

That means if you have a mouse up on an enemy, it will still go to Idle.
You need to check if the mouse Is on an enemy or if it is NOT on an enemy when clicking:

if(Input.GetKeyUp(KeyCode.Mouse0) //<= Clicking anywhere happens ALWAYS
{
    //walk->Idle    This is removed

    if(MouseOverEnemy) // happens only when a enemy is marked
    {
        walk->Attack //so this will happen because the anywhere loop is happening anyways.
    }
    else
    {
        walk->Idle
    }
}

I hope I could clear things up for you. Feel free to ask if you are still having trouble.