You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CrowdControl/Assets/Scripts/AI/FSM_Template/Entities/EnemyDetector.cs

36 lines
883 B
C#

2 months ago
using System.Collections;
using UnityEngine;
public class EnemyDetector : MonoBehaviour // NOTE : Does not handle multiple beast entering/exiting
{
public bool EnemyInRange => _detectedBeast != null;
private Beast _detectedBeast;
private void OnTriggerEnter(Collider other)
{
if (other.GetComponent<Beast>())
{
_detectedBeast = other.GetComponent<Beast>();
}
}
private void OnTriggerExit(Collider other)
{
if (other.GetComponent<Beast>())
{
StartCoroutine(ClearDetectedBeastAfterDelay());
}
}
private IEnumerator ClearDetectedBeastAfterDelay()
{
yield return new WaitForSeconds(3f);
_detectedBeast = null;
}
public Vector3 GetNearestBeastPosition()
{
return _detectedBeast?.transform.position ?? Vector3.zero;
}
}