Animation keeps playing even if input has changed

I’m having some troubles with my animations, for some reason, even if the input has changed, the last animation played keeps playing .To be more specific, if I press W , keep pressing it, my character moves, the running animation plays, but if I press Mouse 0 and then let go the W button, the running animation keeps playing and the shooting one doesn’t. I tried to use layers so I had the shooting animation on layer 1 , while the idle and the running animations were on layer 0. In this case, pressing Mouse 0 did stop the running animation , but it kept shooting even if I stopped pressing Mouse 0 and trying to move the character. I really can’t figure this one out so … any help would be appreciated.This is the Update() function that handles the animations.
In the Inspector, the Wrap Mode is set to Once.

function Update ()
{	
	
	if( Input.GetMouseButtonDown(0)){
				animation["attack"].wrapMode = WrapMode.Once;
				animation["attack"].speed = 1.0;
				animation.CrossFade("attack");

		}

	else if (Input.GetAxis("Vertical") > 0.4 && Health.isAlive)
	{

		animation.wrapMode = WrapMode.Loop;
		animation["run"].speed = 1.0;
		animation.CrossFade ("run");

	}
	
	else if(Input.GetAxis("Vertical") < -0.4 && Health.isAlive )
	{

		animation.wrapMode = WrapMode.Loop;
		animation["run"].speed = -1.0;
		animation.CrossFade ("run");

	}
	
	
	else if(!Input.anyKey && Health.isAlive)
	{
		animation.wrapMode = WrapMode.Loop;
		animation.CrossFade("idle");
	}
	
	
	
}

I tested your code just now and at least for me, this line was enough to solve the problem.
Check if this creates the behaviour you are looking for.
You just need to add this line to your else if statements, for example:

//~ add this condition -> !animation.IsPlaying("attack")
else if (Input.GetAxis("Vertical") > 0.4 && Health.isAlive && !animation.IsPlaying("attack"))
{
    (...)
}