Hi! help please, I am trying to make enemy follow player and change animation from Idle to Walk (follow) but it not working.
public class enemyMove : MonoBehaviour {
public float speed;
private Transform target;
private Animator anim;
bool Triggered;
void Start()
{
target = GameObject.FindGameObjectWithTag("Player").GetComponent<Transform>();
}
private void OnTriggerEnter2D(Collider2D other){
Triggered = true;
}
void Update()
{
if (Triggered == true){
anim.SetBool("Walking", true);
if (Vector2.Distance(transform.position , target.position) > 2){
transform.position = Vector2.MoveTowards(transform.position , target.position , speed * Time.deltaTime);
}
}else{
anim.SetBool("Walking", false);
}
}
}
Comment