Skip to content

Instantly share code, notes, and snippets.

@superspacehero
Created May 3, 2018 06:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save superspacehero/751cec497543044192d44471e836c689 to your computer and use it in GitHub Desktop.
Save superspacehero/751cec497543044192d44471e836c689 to your computer and use it in GitHub Desktop.
AI Group Manager
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