How to play an animation all the way through on a single key press?

I have been on this one issue for more than 3 school days and I'm going insane. haha I've searched, I've problem solved as best I could. Nothing. (I've seen similar questions and they haven't been working.)

Anyway, what I'm trying to do is get an animation to play all the way through on a single key press. I've tried several methods but the closest I got to it working is the boolean method I saw on here. Oddly I got one of the animations to work properly but then the other one doesn't do anything at all.

The script makes perfect sense but it just won't do what I told the other animation to do when both snippets of code are the same thing minus the animation and key names. Any thoughts?

animation die2 works fine. It's die1 that won't do anything.

var die1 : boolean;
var die2 : boolean;

    function Update()
    {
        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            die1 = true;
            die2 = false;
        }

        if (die1)
        {
            animation.CrossFade("die1");
            animation.wrapMode = WrapMode.ClampForever;
        }

        if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            die2 = true;
            die1 = false;
        }

        if (die2)
        {
            animation.CrossFade("die2");
            animation.wrapMode = WrapMode.ClampForever;
        }

        else
        {
            animation.CrossFade("idle");
            animation.wrapMode = WrapMode.Loop;
        }
    }

function Update(){

if(Input.GetKeyDown(KeyCode.W)){ //i just choose w as a random key change this to whatever key you want to play the animation

animation.Play ("Name of your animation"); } }

//if you want to have all other animations stop when this one plays use

//animation.Play ("Name of your animation", PlayMode.StopAll);

hope this helps. make sure you have the correct name for the animation and you spell it right with case sensitivity

if (die1) {
    if(animation.IsPlaying("die1")){

    }else{
          animation.Play("die1");
    }
}

the above code can be used to get an animation to play out fully without stopping on a single key press and even when you press the key again it shouldn't play, just double check that my "IsPlaying" method is used correctly :)

PS. I am also in school :)

var die1 = false;
var die2 = false;

function Start(){
    animation.wrapMode = WrapMode.Loop;

    animation["die1"].wrapMode = WrapMode.ClampForever;
    animation["die2"].wrapMode = WrapMode.ClampForever;

    animation.Stop();

    }

function Update(){

    if (Input.GetKeyDown("Alpha1")){    // you must set this up in the input panel

            animation.CrossFade("die1");
            //die1 = true;   // do you really need the booleans?
           // die2 = false;

        } if (Input.GetKeyDown("Alpha2")){

            animation.CrossFade("die2");
            //die1 = false;
            //die2 = true;

       }else{
            animation.CrossFade("idle");

        }
    }

This is what I did. This seems to work just fine. Thank you all for your help.

function Start()
{
    animation["die1"].layer = 1;
    animation["die2"].layer = 1;
}

function Update()
{
    if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.2)
    {
        animation.Stop("die1");
        animation.Stop("die2");

        if (Mathf.Abs(Input.GetAxis("Run")) > 0.2)
        {
            animation.CrossFade("run");
        }

        else
        {
            animation.CrossFade("walk");
        }
    }

    else if (Input.GetButton("Fire1"))
    {
        animation.Stop("die1");
        animation.Stop("die2");

        animation["attack1"].wrapMode = WrapMode.Once;
        animation.Play("attack1");
    }

    else if (Input.GetButton("Fire2"))
    {
        animation.Stop("die1");
        animation.Stop("die2");

        animation["attack2"].wrapMode = WrapMode.Once;
        animation.Play("attack2");
    }

    else if (Input.GetKeyDown(KeyCode.Alpha1))
    {
        animation["die1"].wrapMode = WrapMode.ClampForever;
        animation.CrossFade("die1");
    }

    else if (Input.GetKeyDown(KeyCode.Alpha2))
    {
        animation["die2"].wrapMode = WrapMode.ClampForever;
        animation.CrossFade("die2");
    }

    else
    {
        animation.CrossFade("idle");
    }
}