How do i make my wave spawner script so i have multiple enemies and the enemy count and enemy types get harder after time?
heres my wave spawner code:
using UnityEngine;
using System.Collections;
public class WaveSpawner : MonoBehaviour
{
public GameObject enemyPrefab;
private int enemyCount;
private int waveNumber = 1;
public float timeBetweenEnemySpawn;
public float timeBetweenWaves;
public Transform[] spawnPoints;
bool spawningWave;
// Start is called before the first frame update
void Start()
{
StartCoroutine(SpawnEnemyWave(waveNumber));
}
// Update is called once per frame
void Update()
{
enemyCount = FindObjectsOfType<Enemy>().Length;
if (enemyCount == 0 && !spawningWave)
{
waveNumber++;
StartCoroutine(SpawnEnemyWave(waveNumber));
}
}
IEnumerator SpawnEnemyWave(int enemiesToSpawn)
{
spawningWave = true;
yield return new WaitForSeconds(timeBetweenWaves); //We wait here to pause between wave spawning
for (int i = 0; i < enemiesToSpawn; i++)
{
Instantiate(enemyPrefab, spawnPoints[Random.Range(0, spawnPoints.Length)].position, enemyPrefab.transform.rotation);
yield return new WaitForSeconds(timeBetweenEnemySpawn); //We wait here to give a bit of time between each enemy spawn
}
spawningWave = false;
}
}
I think you answered your own question…you just need to increase the number of enemies and their difficulty (health? speed? weapons? position?) as waveNumber goes up. Playtesting is key here.
I’ve written a wave spawner template a long time ago. You can find it over here. new discussions link. Note that the actual spawning has been left our. It could be a simple Instantiate call or if you want to use enemy pools you could modify the system to work with pools instead of prefab references.
Also note that my spawner is also a time based spawner. So it does not track how many enemies are left in the current wave before spawning the next one.
If you don’t understand how it works, feel free to ask questions. However please take a look at the comments below my answer. A lot questions have been answered there.
well, i want to make the wave spawner infinite so i dont have to manually make every single wave…also i dont know how to make infinite wave spawner with multiple enemies so that is why i am asking ;-;
It is an infinite spawner. You just haven’t looked at it carefully ^^. It’s extremely flexible and can be configured mainly through the inspector. The waves you set up are executed in order. When you read the end it will repeat from the beginning. You can setup almost any scenario you can think of at least it’s just a time based spawner.
Note that this is meant as a template, not as a plug and play one-size-fits-all solution.
Currently a single wave action can only spawn a certain number of enemies of one type. You can setup several actions per wave to specify multiple different enemies within the same wave. However if you like to support completely random selection of enemies, you can replace the prefab field in the wave action with an array and instead of just instantiating that prefab you could simply pick a random one out of that list. Almost every game that works on “waves” do have some kind of spawn pattern. For example every 5 or 10 waves there is a boss wave. So you could simple design 6 waves (could be 5 identical ones) and a boss wave. Those would be repeated endlessly. Each time the cycle starts over, the spawn time is decreased in order to increase the difficulty. If you want other factors to change (maybe enemy health or enemy count per wave / spawn action) you can do this as well. Just add your desired changes to the code.
You can, you just need to figure out how much to increase the values each wave (can be in a random range too). Then you add those values every time a new wave is created. Will need some sort of cap of difficulty too (probably).
first of all, don’t necropost, its annoying and rly infuriating to EVERYONE in the thread
second, the way I would approach what ur saying is to have a variable as the actual script of the enemy that you want to spawn
then maybe have a int that is the amount you want it to go up by every wave, then before you spawn them, add that int to the enemy starting health
or u could just have multiple prefabs of the enemy