Character Animation idle

how can I get my character to default "idle" when nothing else is being pushed?? Here's my code... sorry its sloppy.

`

var speed = 3.0;
var rotateSpeed = 3.0;
function Update () {
var controller : CharacterController = GetComponent(CharacterController);

//Rotate around y - axis
transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);

//Move Forward / Backward
var forward = transform.TransformDirection(Vector3.forward);
var curSpeed = speed * Input.GetAxis("Vertical");
controller.SimpleMove(forward * curSpeed);
if(Input.GetAxis("Vertical")){
    animation.CrossFade("walk");
}
    if(Input.GetAxis("Horizontal")){
    animation.CrossFade("walk");

} function Start () { animation.Stop(); animation.Play("idle"); animation.wrapMode = WrapMode.Loop;

animation["run"].layer = -1;
animation["walk"].layer = -1;
animation["idle"].layer = -2;
animation.SyncLayer(-1);
var attack = animation["attack"];
attack.wrapMode = WrapMode.Once;
animation.Stop();
animation.Play("idle");

}

@script RequireComponent(CharacterController)`

Just add

if (!animation.isPlaying){
    animation.Play("idle");
}

to your function update.

Just use a simple if statement to see if the character is moving or not. If the speed is less than 0.1 then play the idle animation.

if (Mathf.Abs(Input.GetAxis("Vertical")) <= 0.1){
        animation.CrossFade("Idle");
    }

thank you so much iv ben stuck for a moth on idle animation i love you thank you thank you thank you so so so so so so much