Hello I've been working on this C# strip for last few days trying to figure out how to spawn 1 unit. I figured out how to spawn many units as a continuous loop but I don't know how to spawn just one unit at a Pacific time I'm hoping that there is someon Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; public class Spanwer : MonoBehaviour { public GameObject Enemy; public Transform[] spawnSpots; private float timeBtwSpawns; public float startTimeBtwSpawns; private void Start(){ timeBtwSpawns = startTimeBtwSpawns; } private void Update() { if(timeBtwSpawns <= 0){ int randPos = Random.Range(0, spawnSpots.Length); Instantiate(Enemy, spawnSpots[randPos].position, Quaternion.identity); timeBtwSpawns = startTimeBtwSpawns; }else{ timeBtwSpawns -= Time.deltaTime; } } } e out there that could help me with this small issue any and all help is welcome.
Code (CSharp): IEnumerable SpawningMachin() { while(true) { yield return new WaitForSecondsRealtime(2); Instantiate(Enemy, spawnSpots[randPos].position, Quaternion.identity); } } Try IEnumerable
Or Invoke. Code (CSharp): public float timeBeforeSpawn; // will spawn this many seconds after start void Start () { Invoke ("SpawnThing", timeBeforeSpawn); } private void SpawnThing () { Instantiate (Enemy, spawnSpots[randPos].position, Quaternion.identity); }
Shouldn't the co-routine variant be: Code (CSharp): IEnumerable SpawningMachin() { yield return new WaitForSecondsRealtime(2); Instantiate(Enemy, spawnSpots[randPos].position, Quaternion.identity); } Else it will repeat, rather than be a one shot.