If this Key is pressed do this animation

this problem is currently stopping me from advancing in unity3d. I have seen the mecanim tutorial and I read the BotController script(it was in C# and i use java so i don’t understand it). What I want to do is make it so that when e.g. The w key is pressed, it makes a transition to the walk animation and if i let go it goes back to idle

Hello, tinashee, you can use animation.CrossFade, here is the code:

JS:

var player : GameObject;

function Update()
{
    if(Input.GetKeyDown(KeyCode.W))
    {
        player.animation.CrossFade("Walk");
    }

    if(!Input.anyKey)
    {
        player.animation.CrossFade("Idle");
    }
}

C#

   public GameObject player;
    
    void Update()
    {
        if(Input.GetKeyDown(KeyCode.W))
        {
            player.animation.CrossFade("Walk");
        }
    
        if(!Input.anyKey)
        {
            player.animation.CrossFade("Idle");
        }
    }