2019-08-03 17:36:17 +02:00
|
|
|
|
using UnityEngine;
|
2019-08-14 16:32:52 +02:00
|
|
|
|
using UnityEngine.Animations;
|
2019-08-03 17:36:17 +02:00
|
|
|
|
using Saltosion.OneWeapon.AI;
|
2019-08-14 16:48:17 +02:00
|
|
|
|
using Saltosion.OneWeapon.Utils;
|
2019-08-03 17:36:17 +02:00
|
|
|
|
|
2019-08-14 16:17:48 +02:00
|
|
|
|
namespace Saltosion.OneWeapon.Enemies {
|
2019-08-03 17:36:17 +02:00
|
|
|
|
[RequireComponent(typeof(Rigidbody2D))]
|
|
|
|
|
public class Enemy : MonoBehaviour {
|
|
|
|
|
public float MoveSpeed;
|
2019-08-14 16:48:17 +02:00
|
|
|
|
public AcceleratedMovement Movement;
|
2019-08-14 18:05:41 +02:00
|
|
|
|
[Header("Debug Info")]
|
|
|
|
|
public TextMesh BehaviourDisplay;
|
|
|
|
|
public string CurrentBehaviour = "Nothing";
|
2019-08-04 20:09:00 +02:00
|
|
|
|
|
|
|
|
|
[HideInInspector]
|
|
|
|
|
public bool Attacking;
|
2019-08-03 17:36:17 +02:00
|
|
|
|
|
|
|
|
|
private Rigidbody2D Body;
|
|
|
|
|
private bool MovingToTarget = false;
|
|
|
|
|
private Vector2 TargetPosition;
|
|
|
|
|
|
|
|
|
|
private void Start() {
|
|
|
|
|
Body = GetComponent<Rigidbody2D>();
|
2019-08-14 18:05:41 +02:00
|
|
|
|
BehaviourDisplay.GetComponent<MeshRenderer>().sortingLayerName = "Debug Text";
|
2019-08-03 17:36:17 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Update() {
|
2019-08-14 18:05:41 +02:00
|
|
|
|
bool DisplayDebugInfo = false;
|
|
|
|
|
if (Application.isEditor) {
|
|
|
|
|
Collider2D Hit = Physics2D.OverlapPoint(Camera.main.ScreenToWorldPoint(Input.mousePosition));
|
|
|
|
|
if (Hit != null && Hit.attachedRigidbody == Body) {
|
|
|
|
|
DisplayDebugInfo = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
BehaviourDisplay.gameObject.SetActive(DisplayDebugInfo);
|
|
|
|
|
if (DisplayDebugInfo) {
|
|
|
|
|
BehaviourDisplay.text = CurrentBehaviour;
|
2019-08-04 20:09:00 +02:00
|
|
|
|
}
|
2019-08-03 17:36:17 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FixedUpdate() {
|
|
|
|
|
if (MovingToTarget) {
|
2019-08-14 16:48:17 +02:00
|
|
|
|
Movement.Direction = (TargetPosition - Body.position).normalized;
|
|
|
|
|
} else {
|
|
|
|
|
Movement.Direction = Vector2.zero;
|
2019-08-03 17:36:17 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void StartMovingTo(Vector2 target) {
|
|
|
|
|
TargetPosition = target;
|
|
|
|
|
MovingToTarget = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void StopMoving() {
|
|
|
|
|
MovingToTarget = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|