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.

67 lines
1.6 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 penguinReset;
public PositionReset iceBlockReset;
private void Start()
{
BearAwareness.HasWokenUp += IsAwake;
}
private void Update()
{
if (wakingUp)
{
timer += Time.deltaTime;
bearTimer.fillAmount = timer / bearAwareness.timeToWakeUp;
}
}
public void IsAwake(float time)
{
wakingUp = true;
StartCoroutine(SleepIsOver(time));
}
IEnumerator SleepIsOver(float time)
{
yield return new WaitForSeconds(time);
Vector3 direction = Penguin.position - transform.position;
float distance = direction.magnitude;
direction.Normalize(); // Wichtig: Raycast braucht eine normierte Richtung
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!");
penguinReset.Reset();
iceBlockReset.Reset();
}
else
{
Debug.Log("What?");
}
}
wakingUp = false;
timer = 0f;
bearTimer.fillAmount = 0;
Debug.DrawLine(transform.position, Penguin.position, Color.red, 10f);
}
}