You've already forked zumbi-game
zombie + spawner
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user