Override animation with another

Hello, Thanks for viewing my question. I’ve been using Unity3D for 2 days, never scripted with javascript. I have 5 animations. Sword idle, Sword run, Sword run side, Sword attack, and Sword attack rightside. and the movement animations activate when you move horizontally, or vertically. The problem being, I can’t use my sword attack or sword attack rightside while moving. I can attack if i stay still. Heres my script.

function Update() {

    if(Input.GetMouseButtonDown(0))
    animation.CrossFadeQueued("Sword_attack", 0.3, QueueMode.PlayNow);
          // play sword attack when left click is pressed
    
     if(Input.GetMouseButtonDown(1))
     animation.CrossFadeQueued("Sword_attack_rightside", 0.3, QueueMode.PlayNow);
          // play right side attack when right click is pressed
        
    if(Mathf.Abs(Input.GetAxis("Vertical")) > 0.1) 
// if moving forward or backward, play the running animation
        animation.CrossFade("Sword_run", 0.2);
    else
        animation.PlayQueued("Sword_idle");
// if you aren't running, switch back to the idle animation.
        if (Mathf.Abs(Input.GetAxis("Horizontal")) > 0.1)
        animation.CrossFade("Sword_run_side");
// if moving right or left, play the side step animation.
}

Can you guys help me at all?

Look at the big animation page about layers, partial… and tricks to set up a system. Right now they are all on layer 0, so playing one will cancel anything else. Idle is working because PlayQueue specifically waits for Attack to finish.

Set the attack animation to layer 1+ and it will “win,” covering up layer 0 animations while it plays.