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.

69 lines
1.5 KiB

using System;
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
public class BearAwareness : MonoBehaviour
{
private int awareness;
public Slider awarenessSlider;
public Image SilderColor;
public static event Action<float> HasWokenUp;
public float timeToWakeUp = 2f;
// 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(10));
}
private void Update()
{
if (awareness >= (awarenessSlider.maxValue - 10))
{
SilderColor.color = Color.red;
}
else if (awareness >= (awarenessSlider.maxValue / 2))
{
SilderColor.color = Color.orange;
}
else if (awareness <= (awarenessSlider.maxValue / 2) )
{
SilderColor.color = Color.darkGreen;
}
}
void IncreaseAwareness(int noice)
{
awareness += noice;
awarenessSlider.value = awareness;
if (awareness >= awarenessSlider.maxValue)
{
Debug.Log("Bear is awake now!");
HasWokenUp.Invoke(timeToWakeUp);
}
}
IEnumerator Decrease(float delay)
{
while (true)
{
yield return new WaitForSeconds(5);
awarenessSlider.value -= 5;
}
}
}