I am a little bit new at unity, and now I was trying to make enemies.
I started like the way how I started with making a player until I wanted to set **the walking animation.** The walking animation should start, **when the speed float is greater then 0.1**, I did the same for the player.
Now, and for some reason, **the walking animation of the *enemy* starts, when the *player* moves, even though the *enemy* is not moving.**
How can I fix that?
here is the code of the enemy:
public class Enemy : MonoBehaviour {
public Animator animator;
Rigidbody2D rb2d;
public float runSpeed = 40f;
float horizontalMove = 0f;
void Start()
{
rb2d = GetComponent();
}
void Update()
{
horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;
animator.SetFloat("speed", Mathf.Abs(horizontalMove));
}
}
Thanks.
↧