Get walk animation to play on horizontal and vertical axis presses.

I have this script:

function Update () {
if (Input.GetAxis("Vertical")) {

animation.CrossFade("Walk");
}
else {
animation.CrossFade("Idle");
}
if (Input.GetAxis("Horizontal")) {
animation.CrossFade("Walk");
} else {
animation.CrossFade("Idle");
}
}

what i want to happen is that if the player presses either the horizontal or vertical axis buttons, to play the walk cycle, and if not, play the idle. However when i use this script it will play the walk on the horizontal key presses but not on the vertical ones. How do I solve this?

Your vertical input is completely ignored because your "if-else" block for horizontal input will always override what the vertical input did.

What you probably want is:

function Update () 
{
    if (Input.GetAxis("Vertical")) 
    {
        animation.CrossFade("Walk");
    }
    else if(Input.GetAxis("Horizontal")) 
    {
        animation.CrossFade("Walk");
    } 
    else 
    {
        animation.CrossFade("Idle");
    }
}

Or something similar

function Update () 
{
    if (Input.GetAxis("Vertical") || Input.GetAxis("Horizontal")) 
    {
        animation.CrossFade("Walk");
    }    
    else 
    {
        animation.CrossFade("Idle");
    }
}

Same as above, honestly, except you only have one condition and one default. If you're unfamiliar with script, "||" means "OR".