Animation Clash

I have three animation for my gun; idle, walk and run I have wrote this script so that if nothing is being pressed idle is played if any of the WASD keys are pressed walk plays and if left shift is held run plays. But when left shift is held nothing happens I think its because the animation are clashing can anyone help me please?

function Start () {

animation.wrapMode = WrapMode.Loop;
animation["gun idle"].speed = 0.5;
animation["gun walk"].speed = 2.5;
animation["gun run"].speed = 3;
}

function Update () {

if(Mathf.Abs(Input.GetAxis("Vertical")) > 0.1){
  animation.CrossFade("gun walk");
}
  else{
  animation.CrossFade("gun idle");
}

if(Input.GetAxis("Horizontal") < 0){
  animation.CrossFade("gun walk");
}

if(Input.GetAxis("Horizontal") > 0.1f){
  animation.CrossFade("gun walk");
}

if(Input.GetKeyDown("left shift")){
  animation.CrossFade("gun run");
}
  
if(Input.GetKeyUp("left shift")){
  animation.Stop("gun run");
}
}

I don’t have much experience with animation, but the logic of what you’re doing seems a little off. Do you really want to crossfade both walk and run when running? Maybe try something like the below:

function Update () {
	
	if( (Mathf.Abs(Input.GetAxis("Vertical")) > 0.1) ||
	    (Input.GetAxis("Horizontal") < 0) ||
	    (Input.GetAxis("Horizontal") > 0.1f)){
	   
	   // Character is moving; now find out whether they're running or walking.
	   if( (Input.GetKeyDown("left shift")) )
	   {
	   	  animation.CrossFade("gun run");
	   }
	   else
	   {
	   	   	animation.CrossFade("gun walk");

	   	   	// If this doesn't work, try removing this "if" and just 
	   	   	// always stopping the run animation when you're walking.  
   	   	   	// Not sure if this is allowed or not.
	   	   	if(Input.GetKeyUp("left shift")){
	  			animation.Stop("gun run");
			}
		}
	}
	else{
		// Character is stationary.
		animation.CrossFade("gun idle");
	}
	
}

I think I’ve got it. The documentation for GetKeyDown implies that it only triggers once, during the frame that the user presses the key. You need to change the logic to account for this. Try the following code:

var running = false;

function Update () {

	if( Input.GetKeyDown("left shift") )
	{
		running = true;
	}
    else if ( Input.GetKeyUp("left shift") )
    {
    	running = false;
    }
       
    if( (Mathf.Abs(Input.GetAxis("Vertical")) > 0.1) ||
        (Input.GetAxis("Horizontal") < 0) ||
        (Input.GetAxis("Horizontal") > 0.1f)){

		// Character is moving.
		if (running)
		{
			animation.CrossFade("gun run");
		}
		else
		{
			// Might also need to uncomment the following line,
			// but try it without first.
			// animation.Stop("gun run");
			animation.CrossFade("gun walk");
		}
    }
    else{
       // Character is stationary.
       animation.CrossFade("gun idle");
    }

}

Hopefully that does the trick!

-Kevin