BloodAndGore/Assets/Scripts/Enemies/Crab.cs

53 lines
1.9 KiB
C#
Raw Normal View History

2019-08-14 18:05:41 +02:00
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(Wander))]
[RequireComponent(typeof(Follow))]
[RequireComponent(typeof(MeleeAttackFollowed))]
public class Crab : MonoBehaviour {
public Animator Anim;
private Enemy Enemy;
private PlayerSighted FollowTrigger;
private Wander WanderBehaviour;
private Follow FollowBehaviour;
private MeleeAttackFollowed MeleeBehaviour;
private void Start() {
Enemy = GetComponent<Enemy>();
FollowTrigger = GetComponent<PlayerSighted>();
WanderBehaviour = GetComponent<Wander>();
FollowBehaviour = GetComponent<Follow>();
MeleeBehaviour = GetComponent<MeleeAttackFollowed>();
}
private void Update() {
2019-08-14 21:31:58 +02:00
Enemy.CurrentBehaviour = "";
2019-08-14 18:05:41 +02:00
if (FollowTrigger.IsTriggered()) {
FollowBehaviour.Target = FollowTrigger.Player.transform;
if (MeleeBehaviour.TryExecute()) {
2019-08-14 21:31:58 +02:00
Enemy.CurrentBehaviour += "Melee:" + MeleeBehaviour.CurrentStatus + ", ";
}
if (FollowBehaviour.TryExecute()) {
Enemy.CurrentBehaviour += "Follow:" + FollowBehaviour.CurrentStatus;
2019-08-14 18:05:41 +02:00
}
} else if (WanderBehaviour.TryExecute()) {
2019-08-14 21:31:58 +02:00
Enemy.CurrentBehaviour += "Wander:" + WanderBehaviour.CurrentStatus;
2019-08-14 18:05:41 +02:00
}
2019-08-14 21:31:58 +02:00
if (MeleeBehaviour.Attacking) {
2019-08-14 18:05:41 +02:00
Anim.Play("Attack");
} else {
Anim.Play("Walk");
}
2019-08-22 20:36:22 +02:00
Anim.SetFloat("Speed", Enemy.Movement.AnimationSpeed);
2019-08-14 18:05:41 +02:00
}
}
}