This repository has been archived on 2023-09-13. You can view files and clone it, but cannot push or open issues or pull requests.
station_obscurum_unity/Assets/Scripts/Enemies/AI/SkinlessMonsterComponent.cs
2023-04-18 00:29:51 -04:00

100 lines
2.8 KiB
C#

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);
}
}
/// <summary>
/// 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.
/// </summary>
/// <param name="obj"></param>
/// <param name="minRange"></param>
/// <param name="minMargin"></param>
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;
}