-
-
Save superspacehero/751cec497543044192d44471e836c689 to your computer and use it in GitHub Desktop.
AI Group Manager
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEngine.UI; | |
public class EnemyManager : MonoBehaviour { | |
public Vector3 playerLocationSeen; | |
public Slider timerSlider; | |
private Animator timerAnimator; | |
private Image timerFill; | |
public bool alerting; | |
public bool alert; | |
public float currentAlertTime; | |
public float alertTime = 15; | |
public bool canSeePlayer; | |
private bool timerSliderPopUp; | |
private AudioSource alertSound; | |
void Start() | |
{ | |
currentAlertTime = alertTime; | |
timerAnimator = timerSlider.gameObject.GetComponent<Animator>(); | |
timerFill = timerSlider.GetComponentInChildren<Image>(); | |
timerSlider.maxValue = alertTime; | |
timerSlider.value = alertTime; | |
alertSound = GetComponent<AudioSource>(); | |
} | |
void Update () | |
{ | |
alerting = false; | |
if (alert) | |
{ | |
if (!timerSliderPopUp) | |
{ | |
alertSound.Play(); | |
timerAnimator.SetTrigger("PopUp"); | |
timerSliderPopUp = true; | |
} | |
currentAlertTime -= Time.deltaTime; | |
timerSlider.value = currentAlertTime; | |
if (currentAlertTime <= 0) | |
{ | |
currentAlertTime = alertTime; | |
alert = false; | |
} | |
} | |
else | |
timerSliderPopUp = false; | |
canSeePlayer = false; | |
timerFill.enabled = alert; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment