70 lines
1.5 KiB
C#
70 lines
1.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class WhackSpawnManager : MonoBehaviour
|
|
{
|
|
public int maxSpawned = 2;
|
|
public int waveCount = 0;
|
|
private int spawnLimit = 6;
|
|
private int spawned = 0;
|
|
private float computeTime = 2;
|
|
public static WhackSpawnManager instance;
|
|
private List<WhackSpawner> spawners = new List<WhackSpawner>();
|
|
private int waveCounter, currentSpawned;
|
|
|
|
public void Awake()
|
|
{
|
|
instance = this;
|
|
StartCoroutine(NormalOperation());
|
|
}
|
|
|
|
IEnumerator NormalOperation()
|
|
{
|
|
for (; ;)
|
|
{
|
|
yield return new WaitForSeconds(computeTime);
|
|
if (CanSpawn() && WhackManager.instance.canPlay)
|
|
{
|
|
PickRandomSpawner();
|
|
}
|
|
}
|
|
}
|
|
|
|
public void UpWave()
|
|
{
|
|
waveCount++;
|
|
if (maxSpawned < spawnLimit)
|
|
{
|
|
maxSpawned++;
|
|
}
|
|
if (computeTime > .5f)
|
|
{
|
|
computeTime -= .5f;
|
|
}
|
|
Debug.Log(waveCount);
|
|
}
|
|
|
|
public void PickRandomSpawner()
|
|
{
|
|
if (spawners.Count == 0)
|
|
{
|
|
spawners.AddRange(GetComponentsInChildren<WhackSpawner>());
|
|
}
|
|
spawners[Random.Range(0, spawners.Count)].SpawnEnemy();
|
|
}
|
|
|
|
public bool CanSpawn()
|
|
{
|
|
if (GameObject.FindGameObjectsWithTag("Virus").Length >= maxSpawned)
|
|
{
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
}
|