Animation play on input, else play idle animation.

function Update () {
if (Input.GetKeyDown(“d”)) {
animation.Play(“Walking”);
}
else animation.Play(“Standing”);
}
}

**This is the code i´ve come up with(i´m very new to scripting).
It doesn´t play the Walking animation and apparently can´t find the Standing animation, but plays it anyway. Any help is appreciated, thanks in advance! :slight_smile: **

var walking : boolean = false;

if(input.GetButtonDown("w")) {
   walking = true;

if(walkin == true){
    animation.CrossFade("walking");
    animation.Play();
}

else if (walking == false){
    animation.CrossFade("idle");
    animation.Play();
}

}

For the walking animation:

Use Input.GetKey("d"). Input.GetKeyDown("d") would only execute once, as the key is detected as being pressed down, whereas Input.GetKey("d") will return true for every update that the key is down.

As for the “Standing” animation, make sure the name is correct, and the animation is accessible to the component.

[EDIT] You also may want to add

if(Input.GetKeyUp("d"))
{
    animation.Stop("Walking");
}

Before switching animations.