using System; using System.Collections; using UnityEngine; using UnityEngine.UI; public class BearAwareness : MonoBehaviour { public int awareness; public Slider awarenessSlider; public Image SilderColor; public static event Action HasWokenUp; public float timeToWakeUp = 4f; public AudioClip Awake; public static bool isPaused = false; // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { awareness = 0; awarenessSlider.value = 0; Noice.OnMakeNoice += IncreaseAwareness; StartCoroutine(Decrease(2)); } private void Update() { ChangeSliderColor(); } void IncreaseAwareness(int noice) { //awareness += noice; awarenessSlider.value += noice; if (awarenessSlider.value >= awarenessSlider.maxValue) { isPaused = true; SoundEffectManager.Play("Alert"); BackgroundManager.StopBG(); BackgroundManager.PlayBG(true,Awake); Debug.Log("Bear is awake now!"); HasWokenUp.Invoke(timeToWakeUp); } } IEnumerator Decrease(float delay) { while (true) { Debug.Log(isPaused); while (isPaused) { Debug.Log("Pause"); } yield return new WaitForSeconds(delay); awarenessSlider.value -= 2; awareness -= 2; SoundEffectManager.Play("Bear Sleep"); } } void ChangeSliderColor() { if (awarenessSlider.value >= (awarenessSlider.maxValue - 10)) { SilderColor.color = Color.red; } else if (awarenessSlider.value >= (awarenessSlider.maxValue / 2)) { SilderColor.color = Color.orange; } else if (awarenessSlider.value <= (awarenessSlider.maxValue / 2) ) { SilderColor.color = Color.darkGreen; } } }