You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
1.9 KiB

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<float> HasWokenUp;
public float timeToWakeUp = 4f;
public AudioClip Awake;
// 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();
if (Input.GetKeyDown(KeyCode.Escape))
{
Application.Quit();
}
}
void IncreaseAwareness(int noice)
{
//awareness += noice;
awarenessSlider.value += noice;
if (awarenessSlider.value >= awarenessSlider.maxValue)
{
SoundEffectManager.Play("Alert");
BackgroundManager.StopBG();
BackgroundManager.PlayBG(true,Awake);
Debug.Log("Bear is awake now!");
HasWokenUp.Invoke(timeToWakeUp);
}
}
IEnumerator Decrease(float delay)
{
while (true)
{
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;
}
}
}