BloodAndGore/Assets/Scripts/Enemies/MobCat.cs

59 lines
2.2 KiB
C#
Raw Normal View History

2019-08-18 20:32:07 +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(RangedAttackFollowed))]
public class MobCat : MonoBehaviour {
2019-08-18 20:32:07 +02:00
public Animator Anim;
2019-08-18 23:55:47 +02:00
public SpriteRenderer SpriteRenderer;
2019-08-18 20:32:07 +02:00
private Enemy Enemy;
private PlayerSighted FollowTrigger;
private Wander WanderBehaviour;
private Follow FollowBehaviour;
private RangedAttackFollowed RangedBehaviour;
private void Start() {
Enemy = GetComponent<Enemy>();
FollowTrigger = GetComponent<PlayerSighted>();
WanderBehaviour = GetComponent<Wander>();
FollowBehaviour = GetComponent<Follow>();
RangedBehaviour = GetComponent<RangedAttackFollowed>();
}
private void Update() {
Enemy.CurrentBehaviour = "";
if (FollowTrigger.IsTriggered()) {
FollowBehaviour.Target = FollowTrigger.Player.transform;
if (FollowBehaviour.TryExecute()) {
Enemy.CurrentBehaviour += "Follow:" + FollowBehaviour.CurrentStatus + ", ";
}
if (RangedBehaviour.TryExecute()) {
Enemy.CurrentBehaviour += "Ranged:" + RangedBehaviour.CurrentStatus;
}
} else if (WanderBehaviour.TryExecute()) {
Enemy.CurrentBehaviour += "Wander:" + WanderBehaviour.CurrentStatus;
}
if (RangedBehaviour.Attacking) {
Anim.Play("Attack");
} else {
Anim.Play("Walk");
}
2019-08-22 20:36:22 +02:00
Anim.SetFloat("Speed", Enemy.Movement.AnimationSpeed);
2019-08-18 23:55:47 +02:00
if (Enemy.Movement.SpeedPercentage > 0.1) {
SpriteRenderer.flipX = Vector2.Dot(Enemy.Movement.Direction, Vector2.left) < 0;
} else {
SpriteRenderer.flipX = Vector2.Dot(FollowBehaviour.TargetDirection, Vector2.left) < 0;
}
2019-08-18 20:32:07 +02:00
}
}
}