41 lines
1.1 KiB
C#
41 lines
1.1 KiB
C#
using UnityEngine;
|
|
using Saltosion.OneWeapon.AI;
|
|
|
|
namespace Saltosion.OneWeapon {
|
|
[RequireComponent(typeof(Rigidbody2D))]
|
|
public class Enemy : MonoBehaviour {
|
|
public float MoveSpeed;
|
|
public BehaviourNode BehaviourTree;
|
|
[Space(20)]
|
|
public string CurrentBehavior = "Nothing";
|
|
|
|
private Rigidbody2D Body;
|
|
private bool MovingToTarget = false;
|
|
private Vector2 TargetPosition;
|
|
|
|
private void Start() {
|
|
Body = GetComponent<Rigidbody2D>();
|
|
}
|
|
|
|
private void Update() {
|
|
BehaviourTree.Execute(this);
|
|
CurrentBehavior = BehaviourTree.GetExecutedName();
|
|
}
|
|
|
|
private void FixedUpdate() {
|
|
if (MovingToTarget) {
|
|
Body.velocity = (TargetPosition - Body.position).normalized * MoveSpeed;
|
|
}
|
|
}
|
|
|
|
public void StartMovingTo(Vector2 target) {
|
|
TargetPosition = target;
|
|
MovingToTarget = true;
|
|
}
|
|
|
|
public void StopMoving() {
|
|
MovingToTarget = false;
|
|
}
|
|
}
|
|
}
|