fixed time

This commit is contained in:
2024-04-07 00:12:15 +02:00
parent d5102b868d
commit 731c08bb97
4 changed files with 52 additions and 6 deletions

View File

@ -216,4 +216,22 @@ public partial class GameManager : MonoBehaviourSingleton<GameManager>
{
_contextBuffer.Add(context);
}
/// <summary>
/// Removes the given string from the context
/// </summary>
/// <param name="context"></param>
public void RemoveContext(string context)
{
if ( _contextBuffer.Contains(context) )
{
List<string> contextAsList = _contextBuffer.ToArray().ToList();
_contextBuffer.Clear();
contextAsList.Remove(context);
foreach (var c in contextAsList)
{
_contextBuffer.Add(c);
}
}
}
}

View File

@ -40,6 +40,11 @@ public class TimeManager : MonoBehaviourSingleton<TimeManager>
/// </summary>
public DateTime Deadline => _deadline;
/// <summary>
/// Wie viele Sekunden ein Tag im Spiel hat
/// </summary>
public double SecondsPerDay => _secondsPerDay;
/// <summary>
/// Gibt true zurück, wenn die Deadline verpasst wurde.
/// </summary>

View File

@ -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);
}
}
}