This is what i have so far but im planing on change the code. this code help’s spawn the car but it spawns at a specific time so like every 5 secs or so. Im trying to make it so the car only spawn one at a time until it despawns the next one will spawn after it.
using UnityEngine;
using System.Collections;
public class CarController : MonoBehaviour {
public GameObject enemy;
public Vector3 spawnValues;
public int enemyCount;
public float spawnWait;
public float startWait;
public float waveWait;
void Start ()
{
StartCoroutine (SpawnWaves ());
}
IEnumerator SpawnWaves ()
{
yield return new WaitForSeconds (startWait);
while (true)
{
for (int i = 0; i < enemyCount; i++)
{
Vector3 spawnPosition = new Vector3 (Random.Range (-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
Quaternion spawnRotation = Quaternion.identity;
Instantiate (enemy, spawnPosition, spawnRotation);
yield return new WaitForSeconds (spawnWait);
}
yield return new WaitForSeconds (waveWait);
}
}
}