2024-04-06 18:30:26 +02:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using Utility;
|
|
|
|
|
|
|
|
public class ZombieSpawner : MonoBehaviour
|
|
|
|
{
|
|
|
|
[SerializeField]
|
|
|
|
GameObject ZombiePrefab;
|
|
|
|
[SerializeField]
|
|
|
|
private float _spawnRate = 1.0f;
|
|
|
|
[SerializeField, ShowOnly]
|
|
|
|
private float _spawnTimer;
|
|
|
|
|
2024-04-07 00:12:15 +02:00
|
|
|
private float _secondsPerDay;
|
|
|
|
|
2024-04-06 18:30:26 +02:00
|
|
|
// Start wird aufgerufen, bevor das erste Frame gezeichnet wird
|
|
|
|
void Start()
|
|
|
|
{
|
2024-04-07 00:12:15 +02:00
|
|
|
_secondsPerDay = (float)TimeManager.Instance.SecondsPerDay;
|
|
|
|
_spawnTimer = _secondsPerDay / _spawnRate;
|
2024-04-06 18:30:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update wird einmal pro Frame aufgerufen
|
|
|
|
void Update()
|
|
|
|
{
|
|
|
|
_spawnTimer -= Time.deltaTime;
|
|
|
|
|
|
|
|
if (_spawnTimer <= 0)
|
|
|
|
{
|
2024-04-06 21:43:51 +02:00
|
|
|
Instantiate(ZombiePrefab, transform.position, Quaternion.identity, transform);
|
2024-04-07 00:12:15 +02:00
|
|
|
_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);
|
2024-04-06 18:30:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|