Why is my character animation not working ?

Hi guys, quick question. I have no idea why my animation script is not working entirely.
The first part, the trot animation works. Also the last ‘else’ statement is also working. The rest of the buttons like jumping and sprinting aren’t working.

This is the java script that controls the animations for a horse character. Any thoughts would be welcome.

function Update ()
{

if(Input.GetAxis("Horizontal") || Input.GetAxis("Vertical"))
	{
		animation.CrossFade("trot");
	}
	
	else if(Input.GetAxis("Horizontal") && Input.GetKeyDown(KeyCode.LeftShift))
	{
		animation.CrossFade("run");
	}
	
	else if(Input.GetAxis("Vertical") && Input.GetKeyDown(KeyCode.LeftShift))
	{
		animation.CrossFade("run");
	}
	
	else if(Input.GetKeyDown(KeyCode.Space))
	{
		animation.CrossFade("jump_only");
   	}
	
	else if(Input.GetAxis("Horizontal") && Input.GetKeyDown(KeyCode.LeftShift) && Input.GetKeyDown(KeyCode.Space))
	{
		animation.CrossFade("run_and_jump");
	}
	
	else if(Input.GetAxis("Vertical") && Input.GetKeyDown(KeyCode.LeftShift) && Input.GetKeyDown(KeyCode.Space))
	{
		animation.CrossFade("run_and_jump");
	}
	
	else
	{
		animation.CrossFade("idle");
	}

}

You must get rid of your else’s. The first and last work because whenever you are holding up, down or left or right you are trotting. If you are not holding one of these then you idle.

As soon as your original if statement is true it will skip all the rest because they are only asking things if the original statement is false. Hence the else.

if(Input.GetAxis("Horizontal") || Input.GetAxis("Vertical"))
{
    animation.CrossFade("trot");
 
    if(Input.GetKeyDown(KeyCode.LeftShift))
    {
        animation.CrossFade("run");

        if(Input.GetKeyDown(KeyCode.Space))
        {
            animation.CrossFade("run_and_jump");
        }
    }

    if(Input.GetKeyDown(KeyCode.Space))
    {
        animation.CrossFade("jump_only");
    }
}
else
{
    animation.CrossFade("idle");
}

Remember that an ‘if’ statement inside an ‘if’ statement is an && because it requires both to be true to execute the code inside. So by putting

if(Input.GetKeyDown(KeyCode.LeftShift))

inside of the

if(Input.GetAxis(“Horizontal”) || Input.GetAxis(“Vertical”))

statement. You are saying

if((Horizontal or Vertical) && LeftShift)
{
Do this.
}