This commit is contained in:
2026-01-25 19:36:51 +01:00
parent e38a2b05e7
commit a21f76314f
19 changed files with 841 additions and 50 deletions
+42
View File
@@ -0,0 +1,42 @@
using UnityEngine;
public class BackgroundManager : MonoBehaviour
{
private static AudioSource audioSource;
public AudioClip BG;
private void Awake()
{
audioSource = GetComponent<AudioSource>();
}
void Start()
{
if (BG != null)
{
PlayBG(false,BG);
}
}
public static void PlayBG(bool resetSong, AudioClip clip = null)
{
if (clip != null)
{
audioSource.clip = clip;
}
if (audioSource.clip != null)
{
if (resetSong)
{
audioSource.Stop();
}
audioSource.Play();
}
}
public static void StopBG()
{
audioSource.Pause();
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: af6819c62fb95894485dace7bf3f0c4b
+1 -1
View File
@@ -24,7 +24,7 @@ public class SoundEffectLibrary : MonoBehaviour
public AudioClip GetRandomClip(string name)
{
if (!soundDictionary.ContainsKey(name))
if (soundDictionary.ContainsKey(name))
{
List<AudioClip> audioClips = soundDictionary[name];
if(audioClips.Count > 0)
@@ -0,0 +1,43 @@
using System;
using UnityEngine;
using UnityEngine.UI;
public class SoundEffectManager : MonoBehaviour
{
private static AudioSource audioSource;
private static SoundEffectLibrary soundEffectLibrary;
[SerializeField] private Slider sfxSlider;
private void Awake()
{
audioSource = GetComponent<AudioSource>();
soundEffectLibrary = GetComponent<SoundEffectLibrary>();
}
public static void Play(string soundName)
{
AudioClip audioClip = soundEffectLibrary.GetRandomClip(soundName);
if (audioClip != null)
{
audioSource.PlayOneShot(audioClip);
}
}
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
sfxSlider.onValueChanged.AddListener(delegate {OnValueChanged();});
}
public static void SetVolume(float volume)
{
audioSource.volume = volume;
}
public void OnValueChanged()
{
SetVolume(sfxSlider.value);
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 184172b3257bd764283336d08477bacd
+6
View File
@@ -14,6 +14,8 @@ public class BearAwareness : MonoBehaviour
public static event Action<float> HasWokenUp;
public float timeToWakeUp = 2f;
public AudioClip Awake;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
@@ -36,6 +38,9 @@ public class BearAwareness : MonoBehaviour
if (awareness >= awarenessSlider.maxValue)
{
SoundEffectManager.Play("Alert");
BackgroundManager.StopBG();
BackgroundManager.PlayBG(true,Awake);
StopAllCoroutines();
Debug.Log("Bear is awake now!");
HasWokenUp.Invoke(timeToWakeUp);
@@ -52,6 +57,7 @@ public class BearAwareness : MonoBehaviour
awarenessSlider.value -= 2;
awareness -= 2;
SoundEffectManager.Play("Bear Sleep");
}
}
+77 -27
View File
@@ -15,6 +15,9 @@ public class BearIsAwake : MonoBehaviour
public PositionReset[] thingstoReset;
private bool isWaiting = false;
public AudioClip BG;
public AudioClip Awake;
private void Start()
{
BearAwareness.HasWokenUp += IsAwake;
@@ -43,45 +46,90 @@ public class BearIsAwake : MonoBehaviour
{
yield return new WaitForSeconds(time);
Vector3 direction = Penguin.position - transform.position;
float distance = direction.magnitude;
direction.Normalize();
//Vector3 direction = Penguin.position - transform.position;
//float distance = direction.magnitude;
//direction.Normalize();
float elapsed = 0f;
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)
while (elapsed < 2f)
{
foreach (PositionReset things in thingstoReset)
{
if (things.GetComponent<PlayerMove>() != null)
{
things.Reset();
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());
}
}
Debug.DrawLine(transform.position, things.transform.position, Color.red);
}
bearAwareness.awareness = 0;
bearAwareness.awarenessSlider.value = 0;
wakingUp = false;
timer = 0f;
bearTimer.fillAmount = 0;
}
else if(!isWaiting)
{
Debug.Log("What?");
StartCoroutine(DelayedAction());
}
}
elapsed += Time.deltaTime;
}
}
//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);
@@ -97,6 +145,8 @@ public class BearIsAwake : MonoBehaviour
bearTimer.fillAmount = 0;
isWaiting = false;
Debug.Log("Back to Sleep");
BackgroundManager.StopBG();
BackgroundManager.PlayBG(false,BG);
}
}
+3
View File
@@ -5,12 +5,15 @@ using UnityEngine.UI;
public class Goal : MonoBehaviour
{
public GameObject WinUI;
public AudioClip Win;
private void OnTriggerEnter(Collider other)
{
if (other.tag == "IceBlock")
{
Debug.Log("Win");
WinUI.SetActive(true);
BackgroundManager.StopBG();
BackgroundManager.PlayBG(false,Win);
}
}
}
+8
View File
@@ -20,6 +20,13 @@ public class IceBlockPush : MonoBehaviour
}
}
private void OnTriggerEnter(Collider other)
{
if (other.GetComponent<CapsuleCollider>())
{
SoundEffectManager.Play("Ice Push");
}
}
private void Push(Vector3 position)
{
Vector3 diffrenceVector = rb.transform.position - position;
@@ -33,5 +40,6 @@ public class IceBlockPush : MonoBehaviour
//Debug.DrawRay(transform.position, directionVector * 3f, Color.red);
rb.AddForce(directionVector * contactForce, ForceMode.Impulse);
}
}
+9
View File
@@ -10,5 +10,14 @@ public class Noice : MonoBehaviour
{
if (other.isTrigger) return;
OnMakeNoice.Invoke(noice);
if (this.GetComponent<BoxCollider>() != null)
{
SoundEffectManager.Play("Ice Crack");
}
else
{
SoundEffectManager.Play("Crash");
}
}
}
+1
View File
@@ -8,6 +8,7 @@ public class Pit : MonoBehaviour
private void OnTriggerEnter(Collider other)
{
if (other.isTrigger) return;
SoundEffectManager.Play("Pit");
startmass = other.GetComponent<Rigidbody>().mass;
other.GetComponent<Rigidbody>().mass = 100;
other.GetComponent<Rigidbody>().mass = startmass;
+15 -1
View File
@@ -3,6 +3,7 @@ using System.Collections;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.UI;
using Random = System.Random;
public class PlayerMove : MonoBehaviour
{
@@ -34,6 +35,8 @@ public class PlayerMove : MonoBehaviour
{
rb = GetComponent<Rigidbody>();
standUp = GetComponentInChildren<StandUpCollider>();
StartCoroutine(MakeSound(7f));
}
void Update()
@@ -113,6 +116,7 @@ public class PlayerMove : MonoBehaviour
{
StartCoroutine(Step(0.3f));
}
}
@@ -135,5 +139,15 @@ public class PlayerMove : MonoBehaviour
}
IEnumerator MakeSound(float delay)
{
while (true)
{
yield return new WaitForSeconds(delay);
SoundEffectManager.Play("Penguin Sound");
}
}
}