using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.AI; public class SkinlessMonsterComponent : MonoBehaviour { [SerializeField] private NavMeshAgent agent; [SerializeField] private SkinlessMonsterAnimator animator; private bool inRangeOfTarget = false; private bool atTarget = false; [SerializeField] private float atTargetDistance = 3; private TargetInformation target; private void Update() { if (target != null) { //Update booleans for movement float distToTarget = Vector3.Distance(target.target.transform.position, agent.transform.position); atTarget = atTargetDistance >= distToTarget; if (target.hasDamageRange) { inRangeOfTarget = target.damageRange <= distToTarget; } else { inRangeOfTarget = false; } //Perform actions. } } /* STANDARD BEHAVIOR: - OnSeeing/Hearing Player: - Run towards Player - OnHearing Bolt: - Run towards bolt - OnSeeing Flare: - Run towards flare if not within (flareRange + flareMargin). - This acts like if you are far enough away that you don't feel the pain of the flare - OnSeeing FlareBeacon: - Run away if within (flareBeaconRange + flareBeaconMargin). */ //Runs towards target. If its meant to be hostile, it will melee attack once in range. public void Target(GameObject obj,bool hostile=false) { if(target.target!= obj) { //target = new TargetInformation(obj,hostile,false,runTowards:true); } } //Runs towards flare such that it stops randomly within margin before range. public void TargetFlare(GameObject obj,float range,float margin) { if(target.target != obj) { //target = new TargetInformation(obj, false, true, range, margin,runTowards:true); } } /// /// Runs away from object. A minimum range is specified where it no longer takes damage, and a minimum margin is /// speicifed where it can stop running. /// /// /// /// public void RunAwayFrom(GameObject obj,float minRange,float minMargin) { if(target.target != obj) { //target = new TargetInformation(obj, false, true, minRange, minMargin, false); } } } class TargetInformation { public GameObject target; public bool isHostile; public bool hasDamageRange; public float damageRange; public float damageMargin; public bool runTowards; }