How to show a "warning" effect before enemy spawns in a 2D shooter?
Hello! I am making a 2D top down shooter and I want there to be a particle effect warning that shows in the place an enemy will spawn before it spawns. I am using a wave spawner system and I cannot figure out how to do this. Here's my Wave Spawner script. I'm not using a coroutine as I can't figure out how to make what I have into a functioning coroutine (but if you know how then pls let me know!)
public class Wave
{
public string waveName;
public int noOfEnemies;
public GameObject[] typeOfEnemies;
public float spawnInterval;
}
public class RandomSpawner : MonoBehaviour
{
public Wave[] waves;
public Transform[] spawnPoints;
private Wave currentWave;
private int currentWaveNumber;
private float nextSpawnTime;
private bool canSpawn = true;
private void Update()
{
currentWave = waves[currentWaveNumber];
SpawnWave();
GameObject[] totalEnemies = GameObject.FindGameObjectsWithTag("Enemy");
if(totalEnemies.Length == 0 && !canSpawn && currentWaveNumber+1 !=waves.Length)
{
currentWaveNumber++;
canSpawn = true;
}
}
void SpawnWave()
{
if(canSpawn && nextSpawnTime < Time.time)
{
GameObject randomEnemy = currentWave.typeOfEnemies[Random.Range(0, currentWave.typeOfEnemies.Length)];
Transform randomPoint = spawnPoints[Random.Range(0, spawnPoints.Length)];
Instantiate(randomEnemy, randomPoint.position, Quaternion.identity);
currentWave.noOfEnemies--;
nextSpawnTime = Time.time + currentWave.spawnInterval;
if(currentWave.noOfEnemies ==0)
{
canSpawn = false;
}
}
}
}
Comment