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.
166 lines
4.9 KiB
166 lines
4.9 KiB
using System;
|
|
using System.Collections;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class BearIsAwake : MonoBehaviour
|
|
{
|
|
public Transform Penguin;
|
|
public Image bearTimer;
|
|
|
|
private float timer = 0f;
|
|
private bool wakingUp = false;
|
|
public BearAwareness bearAwareness;
|
|
|
|
public PositionReset[] thingstoReset;
|
|
|
|
private bool isWaiting = false;
|
|
|
|
public AudioClip BG;
|
|
public AudioClip Awake;
|
|
|
|
public GameObject sleepingBear;
|
|
public GameObject awakeBear;
|
|
|
|
private void Start()
|
|
{
|
|
BearAwareness.HasWokenUp += IsAwake;
|
|
|
|
thingstoReset = FindObjectsOfType<PositionReset>();
|
|
}
|
|
|
|
|
|
|
|
private void Update()
|
|
{
|
|
if (wakingUp)
|
|
{
|
|
timer += Time.deltaTime;
|
|
bearTimer.fillAmount = timer / bearAwareness.timeToWakeUp;
|
|
bearAwareness.awarenessSlider.value = bearAwareness.awarenessSlider.maxValue;
|
|
}
|
|
}
|
|
|
|
public void IsAwake(float time)
|
|
{
|
|
|
|
wakingUp = true;
|
|
StartCoroutine(SleepIsOver(time));
|
|
sleepingBear.SetActive(false);
|
|
awakeBear.SetActive(true);
|
|
}
|
|
|
|
IEnumerator SleepIsOver(float time)
|
|
{
|
|
|
|
yield return new WaitForSeconds(time);
|
|
|
|
//Vector3 direction = Penguin.position - transform.position;
|
|
//float distance = direction.magnitude;
|
|
//direction.Normalize();
|
|
|
|
float elapsed = 0f;
|
|
|
|
while (elapsed < 2f)
|
|
{
|
|
foreach (PositionReset things in thingstoReset)
|
|
{
|
|
if (things.GetComponent<PlayerMove>() != null)
|
|
{
|
|
Vector3 dir = things.transform.position - transform.position;
|
|
float distance = dir.magnitude;
|
|
|
|
if (Physics.Raycast(transform.position, dir.normalized, out RaycastHit hit, distance))
|
|
{
|
|
Debug.Log($"Ray zu {things.name} trifft {hit.collider.name}");
|
|
|
|
if (hit.collider.name == "StandUpCollider")
|
|
{
|
|
Debug.Log("Your Dead!");
|
|
foreach (PositionReset objekts in thingstoReset)
|
|
{
|
|
objekts.Reset();
|
|
SoundEffectManager.Play("Fail");
|
|
}
|
|
|
|
bearAwareness.awareness = 0;
|
|
bearAwareness.awarenessSlider.value = 0;
|
|
|
|
wakingUp = false;
|
|
timer = 0f;
|
|
bearTimer.fillAmount = 0;
|
|
}
|
|
else if(!isWaiting)
|
|
{
|
|
Debug.Log("What?");
|
|
StartCoroutine(DelayedAction());
|
|
bearAwareness.awareness = 25;
|
|
bearAwareness.awarenessSlider.value = bearAwareness.awarenessSlider.maxValue /2;
|
|
}
|
|
}
|
|
|
|
Debug.DrawLine(transform.position, things.transform.position, Color.red);
|
|
}
|
|
}
|
|
elapsed += Time.deltaTime;
|
|
}
|
|
|
|
sleepingBear.SetActive(true);
|
|
awakeBear.SetActive(false);
|
|
|
|
//if (Physics.Raycast(transform.position, direction, out RaycastHit hit, distance))
|
|
//{
|
|
// Debug.Log("Getroffen: " + hit.collider.name);
|
|
// if (hit.collider.name == "StandUpCollider")
|
|
// {
|
|
// Debug.Log("Your Dead!");
|
|
// foreach (PositionReset things in thingstoReset)
|
|
// {
|
|
// things.Reset();
|
|
// }
|
|
//
|
|
// bearAwareness.awareness = 0;
|
|
// bearAwareness.awarenessSlider.value = 0;
|
|
//
|
|
// wakingUp = false;
|
|
// timer = 0f;
|
|
// bearTimer.fillAmount = 0;
|
|
// }
|
|
// else if(!isWaiting)
|
|
// {
|
|
// Debug.Log("What?");
|
|
// StartCoroutine(DelayedAction());
|
|
// }
|
|
//
|
|
//
|
|
//}
|
|
|
|
Debug.DrawLine(transform.position, Penguin.position, Color.red, 10f);
|
|
}
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
SoundEffectManager.Play("Alert");
|
|
BackgroundManager.StopBG();
|
|
BackgroundManager.PlayBG(true,Awake);
|
|
bearAwareness.awareness = 50;
|
|
bearAwareness.awarenessSlider.value = bearAwareness.awarenessSlider.maxValue;
|
|
IsAwake(bearAwareness.timeToWakeUp);
|
|
}
|
|
|
|
IEnumerator DelayedAction()
|
|
{
|
|
isWaiting = true;
|
|
wakingUp = false;
|
|
timer = 0f;
|
|
|
|
yield return new WaitForSeconds(2f);
|
|
bearTimer.fillAmount = 0;
|
|
isWaiting = false;
|
|
Debug.Log("Back to Sleep");
|
|
BackgroundManager.StopBG();
|
|
BackgroundManager.PlayBG(false,BG);
|
|
|
|
}
|
|
}
|