BloodAndGore/Assets/Scripts/AI/Behaviours/Follow.cs

29 lines
874 B
C#

using UnityEngine;
namespace Saltosion.OneWeapon.AI.Behaviours {
public class Follow : AIBehaviour {
public Transform Target;
public float CloseEnoughRadius;
public override bool CanBehave(Enemy subject) {
return true;
}
public override bool Execute(Enemy subject) {
if (Target != null) {
Vector2 position = subject.transform.position;
Vector2 targetPosition = Target.position;
Vector2 delta = targetPosition - position;
if (delta.magnitude > CloseEnoughRadius) {
delta -= delta.normalized * CloseEnoughRadius;
subject.StartMovingTo(position + delta);
return true;
}
}
subject.StopMoving();
return false;
}
}
}