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

29 lines
872 B
C#
Raw Normal View History

2019-08-03 17:36:17 +02:00
using UnityEngine;
namespace Saltosion.OneWeapon.AI.Behaviours {
public class Follow : Behaviour {
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;
}
}
}