Animation problem

Well, I got a little BIG problem. I want to play a animation while the W key is pressed down. It was working: the character was moving when pressing W, and the animation aswell. I have not changed anything in the scripts, but now the animation plays non-stop, and the character is not moving, also there is a big lag. I want the animation to play when any of W,A,S,D is pressed, If you can help me with that.
Help please.

function Start ()
{
	if(Input.GetKeyDown("w"))
	{
		animation.Play("Walk", PlayMode.StopAll);
	}
}

Hi,Why are you calling animation.Play in Start Start as the name suggests only gets called during begining of the level so use **Update ** instead and Dont use GetKeyDown for input that changes constantly instead use GetKey

Try usinmg this snippet

function Update()
{
 if(Input.GetKey(KeyCode.W)) 
{
animation.Play("Walk", PlayMode.StopAll);
}else if(Input.GetKey(KeyCode.A)) // Use KeyCodes much more efficient

{
 animation.Play("WalkLeft", PlayMode.StopAll);
}else if()
{
 //similarly for all key presses
}//finally after all your key press code

else {
animation.Play("Idle", PlayMode.StopAll);
}



}

use the animator.Its really easy to use.there some tutorial in youtube about the animator which can be really useful for your game.

Sample of my script… Use it… I already changed it to support yours try to improvise with it.

if (Input.GetKeyDown(KeyCode.W));
{
   Player.animation.CrossFade("Walk");
}

if (Input.GetKeyUp(KeyCode.W));
{
   Player.animation.CrossFade("Idle");
}

Side Notes:

Player = Character/Model

Idle,Walk = Animation

If your wondering where did I get this script… Try to watch Brackey’s Tutorial… :3