Hi, I don’t have an idea to do with this script, once I finished writing it I’ve realized I done it wrong.
using UnityEngine;
using System.Collections;
namespace Vuforia
{
public class SpawnScript : MonoBehaviour
{
DectectableScript DS;
ZoneManagerScript Zms;
GameObject MonsterPrefab;
GameObject MonsterReference;
public Vector3 Zone1;
public Vector3 Zone2;
public Vector3 Zone3;
public Vector3 Zone4;
public Vector3 Zone5;
void Start()
{
}
public void SpawnInZone1()
{
GameObject ZMSObject = GameObject.FindGameObjectWithTag ("Zone Manager");
Zms = ZMSObject.GetComponent<ZoneManagerScript>();
DS = GetComponent<DectectableScript>();
MonsterReference = GetComponent<DectectableScript>().Monster;
if (Zms.Zone1Empty)
{
MonsterPrefab = Instantiate(MonsterReference,Zone1,Quaternion.identity) as GameObject;
Debug.Log("Monster Spawned In Zone 1");
Zms.Zone1Empty = false;
}
if (!Zms.Zone1Empty)
{
SpawnInZone2();
}
}
void SpawnInZone2()
{
if (Zms.Zone2Empty)
{
MonsterPrefab = Instantiate(MonsterReference,Zone2,Quaternion.identity) as GameObject;
Debug.Log("Monster Spawned In Zone 2");
Zms.Zone2Empty = false;
}
if (!Zms.Zone2Empty)
{
SpawnInZone3();
}
}
void SpawnInZone3()
{
if (Zms.Zone3Empty)
{
MonsterPrefab = Instantiate(MonsterReference,Zone3,Quaternion.identity) as GameObject;
Debug.Log("Monster Spawned In Zone 3");
Zms.Zone3Empty = false;
}
if (!Zms.Zone3Empty)
{
SpawnInZone4();
}
}
void SpawnInZone4()
{
if (Zms.Zone4Empty)
{
MonsterPrefab = Instantiate(MonsterReference,Zone4,Quaternion.identity) as GameObject;
Debug.Log("Monster Spawned In Zone 4");
Zms.Zone4Empty = false;
}
if (!Zms.Zone4Empty)
{
SpawnInZone5();
}
}
void SpawnInZone5()
{
if (Zms.Zone5Empty)
{
MonsterPrefab = Instantiate(MonsterReference,Zone5,Quaternion.identity) as GameObject;
Debug.Log("Monster Spawned In Zone 5");
Zms.Zone5Empty = false;
}
if (!Zms.Zone5Empty)
{
Debug.Log("Zones Full");
}
}
}
}
I want the Monster to spawn once. But since it keeps going it spawned 5 times. I just want an idea how to fix this.
Heres the code with the bool if needed.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace Vuforia
{
public class ZoneManagerScript : MonoBehaviour
{
public bool Zone1Empty;
public bool Zone2Empty;
public bool Zone3Empty;
public bool Zone4Empty;
public bool Zone5Empty;
void Start()
{
Zone1Empty = true;
Zone2Empty = true;
Zone3Empty = true;
Zone4Empty = true;
Zone5Empty = true;
}
}
}