Hello,
I want to fix my script, but I don’t know exactly how to do it and I’ve been googling for awhile now and I haven’t found any help.
I want 3 types of enemies to respawn, but sooner or later the enemies are spawning on top of each other.
What could I use for a solution?
Here’s my script: Enemywave.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Enemywave : MonoBehaviour
{
public Transform enemy1;
public Transform enemy2;
public Transform enemy3;
public float SpawnCount = 3f;
public float WaveCount = 3f;
private int EnemyNum=0;
public Transform whereSpawn;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (WaveCount <= 0)
{
StartCoroutine(EnemyWaveCount());
EnemyWaveCount();
WaveCount = SpawnCount;
}
WaveCount -= Time.deltaTime;
}
IEnumerator EnemyWaveCount()
{
EnemyNum++;
for (int i = 0; i < EnemyNum; i++)
{
Enemy1Spawner();
yield return new WaitForSeconds(1f);
Enemy2Spawner();
yield return new WaitForSeconds(3f);
Enemy3Spawner();
yield return new WaitForSeconds(5f);
}
}
void Enemy1Spawner()
{
Instantiate(enemy1,whereSpawn.position,whereSpawn.rotation);
}
void Enemy2Spawner()
{
Instantiate(enemy2, whereSpawn.position, whereSpawn.rotation);
}
void Enemy3Spawner()
{
Instantiate(enemy3, whereSpawn.position, whereSpawn.rotation);
}
}
What can I do or use in order not to make the enemies to spawn on top of each other?
Thank you