I am making a spawning system for a game I’m working on. It works perfectly fine but enemies spawn on top of each other in massive hordes which not only looks awful, but crashes the engine. The system i have is formatted so that the amount of enemies spawning increases as time goes on. Here is the code.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AlternateSpawningScript : MonoBehaviour
{
// Start is called before the first frame update
public GameObject[] Demons;
public int time1;
public int time2;
public List<int> wave = new List<int>();
void Start()
{
for (int i = 10; i > 1; i -= 1)
{
foreach(int e in wave){
spawningEnemiesInvoke();
wave.Add(i);
}
}
}
// Update is called once per frame
private void FixedUpdate() {
}
void spawningEnemiesInvoke(){
Invoke("spawningEnemies", Random.Range(time1, time2));
}
void spawningEnemies(){
Instantiate(Demons[Random.Range(0, Demons.Length)], transform.position, Quaternion.identity);
}
}