BloodAndGore/Assets/Scripts/AI/Triggers/PlayerSighted.cs

41 lines
1.6 KiB
C#
Raw Normal View History

2019-08-04 17:35:24 +02:00
using UnityEngine;
using Saltosion.OneWeapon.Utils;
2019-08-14 16:17:48 +02:00
using Saltosion.OneWeapon.Player;
using Saltosion.OneWeapon.Enemies;
2019-08-04 17:35:24 +02:00
namespace Saltosion.OneWeapon.AI.Triggers {
public class PlayerSighted : Trigger {
2019-08-14 21:31:58 +02:00
[Tooltip("How close the player needs to be for the AI to notice them.")]
2019-08-04 17:35:24 +02:00
public float Radius;
2019-08-14 21:31:58 +02:00
[Tooltip("How far the player needs to escape for the AI to \"forget\" them.")]
public float ForgetRadius;
[Tooltip("How long does it take for the enemy to forget where the player was?")]
public float ForgetTimer;
2019-08-14 16:17:48 +02:00
public PlayerController Player { get; private set; }
2019-08-04 17:35:24 +02:00
2019-08-14 21:31:58 +02:00
private bool CountdownStarted = false;
private float ForgetCountdownStartTime = 0.0f;
2019-08-14 18:05:41 +02:00
public override bool IsTriggered() {
2019-08-14 21:31:58 +02:00
PlayerController Sighted = Util.GetClosestTo<PlayerController>(transform, Player == null ? Radius : ForgetRadius, true);
if (Sighted != null) {
CountdownStarted = false;
Player = Sighted;
} else if (!CountdownStarted) {
CountdownStarted = true;
ForgetCountdownStartTime = Time.time;
} else if (Time.time - ForgetCountdownStartTime > ForgetTimer) {
Player = null;
}
2019-08-04 17:35:24 +02:00
return Player != null;
}
2019-08-04 19:48:28 +02:00
private void OnDrawGizmosSelected() {
Gizmos.color = Color.green;
Gizmos.DrawWireSphere(transform.position, Radius);
2019-08-14 21:31:58 +02:00
Gizmos.color = new Color(Color.green.r, Color.green.g, Color.green.b, 0.5f);
Gizmos.DrawWireSphere(transform.position, ForgetRadius);
2019-08-04 19:48:28 +02:00
}
2019-08-04 17:35:24 +02:00
}
}