57 lines
2.0 KiB
C#
57 lines
2.0 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using Saltosion.OneWeapon.AI.Behaviours;
|
|
using Saltosion.OneWeapon.AI.Triggers;
|
|
|
|
namespace Saltosion.OneWeapon.Enemies {
|
|
[RequireComponent(typeof(Enemy))]
|
|
[RequireComponent(typeof(PlayerSighted))]
|
|
[RequireComponent(typeof(Follow))]
|
|
[RequireComponent(typeof(ExplodeFollowed))]
|
|
public class Armadillo : MonoBehaviour {
|
|
public Animator Anim;
|
|
public SpriteRenderer SpriteRenderer;
|
|
|
|
private Enemy Enemy;
|
|
private PlayerSighted FollowTrigger;
|
|
private Follow FollowBehaviour;
|
|
private ExplodeFollowed ExplodeBehaviour;
|
|
|
|
private void Start() {
|
|
Enemy = GetComponent<Enemy>();
|
|
FollowTrigger = GetComponent<PlayerSighted>();
|
|
FollowBehaviour = GetComponent<Follow>();
|
|
ExplodeBehaviour = GetComponent<ExplodeFollowed>();
|
|
}
|
|
|
|
private void Update() {
|
|
bool Moving = false;
|
|
Enemy.CurrentBehaviour = "";
|
|
if (FollowTrigger.IsTriggered()) {
|
|
FollowBehaviour.Target = FollowTrigger.Player.transform;
|
|
Enemy.CurrentBehaviour += "PlayerSighted, ";
|
|
} else {
|
|
FollowBehaviour.Target = null;
|
|
}
|
|
if (ExplodeBehaviour.TryExecute()) {
|
|
Enemy.CurrentBehaviour += "Explode:" + ExplodeBehaviour.CurrentStatus + ", ";
|
|
}
|
|
if (FollowBehaviour.TryExecute()) {
|
|
Enemy.CurrentBehaviour += "Follow:" + FollowBehaviour.CurrentStatus;
|
|
Moving = true;
|
|
}
|
|
|
|
if (Moving) {
|
|
Anim.Play("Roll");
|
|
} else {
|
|
Anim.Play("Idle");
|
|
}
|
|
Anim.SetFloat("Speed", Enemy.Movement.AnimationSpeed);
|
|
if (Enemy.Movement.SpeedPercentage > 0.1) {
|
|
SpriteRenderer.flipX = Vector2.Dot(Enemy.Movement.Direction, Vector2.left) < 0;
|
|
}
|
|
}
|
|
}
|
|
}
|