How to make enemy run animation

So how i can do that when enemy is moving then play animation Walk and when he stop then play animation idle ^^ btw can u tell me that script in C#:slight_smile:

In the Update() function you add something like this:

 

      if (Input.GetAxis("Vertical") > 0.2F){
            animation["walk"].speed = 1.0;
            animation.CrossFade("walk");
       }
    else if (Input.GetAxis("Vertical") < -0.2F){
             animation("walk").speed = -1.0;
             animation.CrossFade("walk");
           }
    else{
		animation.CrossFade("idle");
	}

    The normal speed of the playback is 1, so -1 will play the animation backwards.This happens when Input.GetAxis("Vertical") returns a negative value (so you are going backwards).Hope this helps.I don't use C# so pardon me if made a mistake.

I only work with javascript, but Iโ€™m sure itโ€™s simple enough to translate to C#.

Iโ€™ll consider you have some condition to know when the enemy is not moving anymore.
Besides that, I normally use this:

if(moving==false && !animation.IsPlaying("walk") && !animation.IsPlaying("idle")){
    animation.Play("idle");
}

thx guys <3 :slight_smile: