From 731c08bb97007e6b1adba677e811637adf8d04b9 Mon Sep 17 00:00:00 2001 From: klappstuhl24 Date: Sun, 7 Apr 2024 00:12:15 +0200 Subject: [PATCH] fixed time --- 3d Prototyp/Assets/Scenes/GameLoopTest.unity | 8 +++--- 3d Prototyp/Assets/Scripts/GameManager.cs | 18 +++++++++++++ 3d Prototyp/Assets/Scripts/TimeManager.cs | 5 ++++ 3d Prototyp/Assets/Scripts/ZombieSpawner.cs | 27 ++++++++++++++++++-- 4 files changed, 52 insertions(+), 6 deletions(-) diff --git a/3d Prototyp/Assets/Scenes/GameLoopTest.unity b/3d Prototyp/Assets/Scenes/GameLoopTest.unity index f46d0b0e..ae47c011 100644 --- a/3d Prototyp/Assets/Scenes/GameLoopTest.unity +++ b/3d Prototyp/Assets/Scenes/GameLoopTest.unity @@ -267,7 +267,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 0 + m_IsActive: 1 --- !u!114 &37507748 MonoBehaviour: m_ObjectHideFlags: 0 @@ -282,10 +282,10 @@ MonoBehaviour: m_EditorClassIdentifier: IsOn: 0 _turnOnTime: - _hour: 0 + _hour: 21 _minutes: 0 _turnOffTime: - _hour: 0 + _hour: 6 _minutes: 0 --- !u!4 &37507749 Transform: @@ -427,7 +427,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: _daysUntilRelease: 20 - _secondsPerDay: 5 + _secondsPerDay: 30 _totalTime: 0 _sun: {fileID: 179279866} --- !u!4 &227416519 diff --git a/3d Prototyp/Assets/Scripts/GameManager.cs b/3d Prototyp/Assets/Scripts/GameManager.cs index 0a14805e..af831d3a 100644 --- a/3d Prototyp/Assets/Scripts/GameManager.cs +++ b/3d Prototyp/Assets/Scripts/GameManager.cs @@ -216,4 +216,22 @@ public partial class GameManager : MonoBehaviourSingleton { _contextBuffer.Add(context); } + + /// + /// Removes the given string from the context + /// + /// + public void RemoveContext(string context) + { + if ( _contextBuffer.Contains(context) ) + { + List contextAsList = _contextBuffer.ToArray().ToList(); + _contextBuffer.Clear(); + contextAsList.Remove(context); + foreach (var c in contextAsList) + { + _contextBuffer.Add(c); + } + } + } } diff --git a/3d Prototyp/Assets/Scripts/TimeManager.cs b/3d Prototyp/Assets/Scripts/TimeManager.cs index 184f1902..e3e35b04 100644 --- a/3d Prototyp/Assets/Scripts/TimeManager.cs +++ b/3d Prototyp/Assets/Scripts/TimeManager.cs @@ -40,6 +40,11 @@ public class TimeManager : MonoBehaviourSingleton /// public DateTime Deadline => _deadline; + /// + /// Wie viele Sekunden ein Tag im Spiel hat + /// + public double SecondsPerDay => _secondsPerDay; + /// /// Gibt true zurück, wenn die Deadline verpasst wurde. /// diff --git a/3d Prototyp/Assets/Scripts/ZombieSpawner.cs b/3d Prototyp/Assets/Scripts/ZombieSpawner.cs index 28b62b46..611c661d 100644 --- a/3d Prototyp/Assets/Scripts/ZombieSpawner.cs +++ b/3d Prototyp/Assets/Scripts/ZombieSpawner.cs @@ -12,10 +12,13 @@ public class ZombieSpawner : MonoBehaviour [SerializeField, ShowOnly] private float _spawnTimer; + private float _secondsPerDay; + // Start wird aufgerufen, bevor das erste Frame gezeichnet wird void Start() { - _spawnTimer = 60 / _spawnRate; + _secondsPerDay = (float)TimeManager.Instance.SecondsPerDay; + _spawnTimer = _secondsPerDay / _spawnRate; } // Update wird einmal pro Frame aufgerufen @@ -26,7 +29,27 @@ public class ZombieSpawner : MonoBehaviour if (_spawnTimer <= 0) { Instantiate(ZombiePrefab, transform.position, Quaternion.identity, transform); - _spawnTimer = 60 / _spawnRate; + _spawnTimer = _secondsPerDay / _spawnRate; + } + } + + private void OnEnable() + { + if (GameManager.Instance != null) + { + if (GameManager.Instance.ContextBuffer != null) + GameManager.Instance.AddContext("The Developer informs Gottfried that Zombies appeared outside so Gottfried better not leave the office"); + } + } + + private void OnDisable() + { + if (GameManager.Instance.ContextBuffer != null) + GameManager.Instance.RemoveContext("The Developer informs Gottfried that Zombies appeared outside so Gottfried better not leave the office"); + // Destroy all children (zombies) + for (int i = 0; i < transform.childCount; i++) + { + Destroy(transform.GetChild(i).gameObject); } } }