using Enemies.States; using UnityEngine; namespace Enemies { public class PathState : IState { private readonly Enemy context; public PathState(Enemy context) { this.context = context; } public void Enter() { Debug.Log("Entering Path State"); context.currentState = Enemy.States.Path; } public void Execute() { //Determine direction to target Vector2 direction = context.target.transform.position - context.transform.position; //Move in desired direction context.GetComponent().MovePosition((Vector2)context.transform.position + direction.normalized * context.speed * Time.deltaTime); float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg; context.transform.rotation = Quaternion.Euler(0, 0, angle); } public void Exit() { } } }