You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.1 KiB
38 lines
1.1 KiB
using System.Collections.Generic; |
|
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() |
|
{ |
|
LinkedList<Vector2> path = context.GameManager.GetComponent<PathFinding>() |
|
.FindPath(context.transform.position, context.target.transform.position); |
|
Vector2 target = path.First.Value; |
|
Vector2 direction = target - (Vector2) context.transform.position; |
|
context.transform.rotation = Quaternion.Euler(0, 0, Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg); |
|
context.transform.position += (Vector3)(direction * context.speed * Time.deltaTime); |
|
//Set looking direction |
|
|
|
} |
|
|
|
public void Exit() |
|
{ |
|
} |
|
} |
|
} |