i tried to make a random spawn system, but when i tried to start it, it spawns more than 1 prefab, which is not intended as i wanted to spawn only one by one.
tried some method to prevent from spawning non stop, but can't really make it to spawn only one.
EDIT: deleted the random range in the start section, it works as intended at the beginning, however when i enabled the same script in the prefab( based on the gameobject listed), it just spawn endlessly, script for these gameobject will be added, and since they are pretty much the same thing, i'll only attach one of them.
public GameObject Tap, Up, Down, Left, Right;
int WhatToSpawn;
public bool isFree=false;
public bool destroyed=false;
// Use this for initialization
void Start () {
isFree = true;
destroyed = true;
}
// Update is called once per frame
void Update()
{
if (isFree && destroyed)
{
destroyed = false;
isFree = false;
WhatToSpawn = Random.Range(1, 6);
switch (WhatToSpawn)
{
case 1:
Instantiate(Tap, Tap.transform.position, Tap.transform.rotation);
break;
case 2:
Instantiate(Up, Up.transform.position, Up.transform.rotation);
break;
case 3:
Instantiate(Down, Down.transform.position, Down.transform.rotation);
break;
case 4:
Instantiate(Left, Left.transform.position, Left.transform.rotation);
break;
case 5:
Instantiate(Right, Right.transform.position, Right.transform.rotation);
break;
}
}
}
Here's the another script that is made for gameobject, i tried to make conditions that the script will spawn random stuff when destroy but failed to.
private Swipe swipe;
private SpawnManager spawn;
private void Awake()
{
swipe = GetComponent<Swipe>();
spawn = GetComponent<SpawnManager>();
}
// Update is called once per frame
void Update () {
if (swipe.Tap)
{
Debug.Log("Passed!");
spawn.isFree = true;
Destroy(gameObject);
spawn.destroyed = true;
}
else
{if (swipe.SwipeLeft || swipe.SwipeDown || swipe.SwipeRight || swipe.SwipeUp)
{
Debug.Log("Failed...");
spawn.isFree = true;
Destroy(gameObject);
spawn.destroyed = true;
}
}
}