Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

Enemy shouldn't walk with the player

$
0
0
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.

Viewing all articles
Browse latest Browse all 1488

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>