I have a piece of code here. I have a game object that contains a particle and I would Instantiate it and I want to pause or wait for number of seconds then Instantiate the other prefab I have. I have an idea of coroutine but I don’t know how to use it in the context I have. Help.
public class SpawnScript : MonoBehaviour
{
DectectableScript DS;
ZoneManagerScript Zms;
public GameObject MonsterPrefab;
GameObject MonsterReference;
public GameObject ParticleS;
GameObject ParticlePrefab;
SpawnScript SS;
Vector3 Zone1 = new Vector3 (13f, 0f, -6.5f);
Vector3 Zone2 = new Vector3 (6.44f, 0f, -6.5f);
Vector3 Zone3 = new Vector3 (.05f, .0f, -6.5f);
Vector3 Zone4 = new Vector3 (-6.53f, 0f, -6.5f);
Vector3 Zone5 = new Vector3 (-13.39f, 0f, -6.5f);
public int SpawnLimit = 0;
public bool IsInZone1;
public bool IsInZone2;
public bool IsInZone3;
public bool IsInZone4;
public bool IsInZone5;
void Start()
{
IsInZone1 = false;
IsInZone2 = false;
IsInZone3 = false;
IsInZone4 = false;
IsInZone5 = false;
}
public void SpawnInZone1()
{
GameObject ZMSObject = GameObject.FindGameObjectWithTag ("Zone Manager");
Zms = ZMSObject.GetComponent<ZoneManagerScript>();
DS = GetComponent<DectectableScript>();
MonsterReference = GetComponent<DectectableScript>().Monster;
if (Zms.Zone1Empty)
{
ParticlePrefab = Instantiate(ParticleS,Zone1,Quaternion.identity) as GameObject;
MonsterPrefab = Instantiate(MonsterReference,Zone1,Quaternion.identity) as GameObject;
Debug.Log("Monster Spawned In Zone 1");
Zms.Zone1Empty = false;
SpawnLimit ++;
IsInZone1 = true;
}
It’s in the if(Zms.Zone1Empty) statement.