Pingu Art und Bear mechanic
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9d065ef101ba1aa4287712ed4364f254
|
||||
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
public class BearIsAwake : MonoBehaviour
|
||||
{
|
||||
public Transform Penguin;
|
||||
|
||||
|
||||
private void Start()
|
||||
{
|
||||
BearAwareness.HasWokenUp += IsAwake;
|
||||
}
|
||||
|
||||
public void IsAwake(float time)
|
||||
{
|
||||
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!");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("What?");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Debug.DrawLine(transform.position, Penguin.position, Color.red, 10f);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 682ff406ef701fc47849b6c2a3e3473e
|
||||
@@ -0,0 +1,14 @@
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
public class Noice : MonoBehaviour
|
||||
{
|
||||
public static event Action<int> OnMakeNoice;
|
||||
public int noice;
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (other.isTrigger) return;
|
||||
OnMakeNoice.Invoke(noice);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e7bd60a7c0041e044b3f3b515418222e
|
||||
@@ -79,48 +79,6 @@ public class PlayerMove : MonoBehaviour
|
||||
|
||||
}
|
||||
|
||||
private void Move(float _horizontalInput, float _verticalInput)
|
||||
{
|
||||
if (_horizontalInput != 0 && horizontal == true)
|
||||
{
|
||||
if (!standUp.ispushing)
|
||||
{
|
||||
transform.rotation = Quaternion.Euler(0f, 0f, 90f);
|
||||
}
|
||||
vertical = false;
|
||||
moveDirection = new Vector3(_horizontalInput,0, 0);
|
||||
moveDirection.Normalize();
|
||||
|
||||
if (!vertical && speed <= maxspeed && !standUp.ispushing)
|
||||
{
|
||||
speed += speedincrease;
|
||||
}
|
||||
}
|
||||
else if (_verticalInput != 0 && vertical == true)
|
||||
{
|
||||
if (!standUp.ispushing)
|
||||
{
|
||||
transform.rotation = Quaternion.Euler(90f, 0f, 0f);
|
||||
}
|
||||
horizontal = false;
|
||||
moveDirection = new Vector3(0, 0, _verticalInput);
|
||||
moveDirection.Normalize();
|
||||
|
||||
if (!horizontal && speed <= maxspeed && !standUp.ispushing)
|
||||
{
|
||||
speed += speedincrease;
|
||||
}
|
||||
|
||||
}
|
||||
// else
|
||||
// {
|
||||
// StartCoroutine(Slide(slide));
|
||||
// transform.rotation = Quaternion.Euler(0f, 0f, 0f);
|
||||
// }
|
||||
//
|
||||
// transform.Translate(moveDirection * speed * Time.deltaTime, Space.World);
|
||||
//Debug.Log(moveDirection);
|
||||
}
|
||||
|
||||
IEnumerator Slide(float delay)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user