zombie + spawner

This commit is contained in:
2026-04-27 10:23:16 +02:00
parent f7e9858b4f
commit 4ddd24b45b
88 changed files with 189233 additions and 2 deletions
+47
View File
@@ -0,0 +1,47 @@
using System.Collections.Generic;
using UnityEngine;
public class ZombieSpawnerLogic : MonoBehaviour
{
public GameObject Prefab;
public byte CooldownSeconds = 5;
public byte MaxSpawns = 5;
private float _lastSpawn;
private readonly List<GameObject> _spawns = new();
void Start()
{
_lastSpawn = Time.time;
}
void FixedUpdate()
{
RemoveDestroyedZombies();
AttemptZombieSpawn();
}
private void AttemptZombieSpawn()
{
if (Time.time - _lastSpawn < CooldownSeconds)
{
return;
}
if (_spawns.Count >= MaxSpawns)
{
Debug.Log("Cannot spawn zombie, capacity reached");
return;
}
Debug.Log("Spawning zombie");
var newZombie = Instantiate(Prefab, transform);
_spawns.Add(newZombie);
_lastSpawn = Time.time;
}
private void RemoveDestroyedZombies()
{
_spawns.RemoveAll(zombie => zombie == null);
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 6df508712319afd44b6bfceab4396490