Hi, I’m trying to make upgrade crates spawn randomly over time and with the following script it works, but only for one type of crate.
I’ve made 10 different types of crates and I’d like for them al to spawn randomly, one at a time. Here’s my code:
public GameObject crate;
public int xPos;
public int zPos;
public int crateCount;
//public int numSelectors = 10;
//public GameObject[] selectorArr;
//public GameObject selector;
void Start () {
StartCoroutine(CrateDrop());
//selectorArr = new GameObject[numSelectors];
//for (int i = 0; i < numSelectors; i++)
//{
// /*GameObject go = */Instantiate(selector, new Vector3(xPos, 26, zPos), Quaternion.identity);
// //selectorArr[i] = go;
//}
}
IEnumerator CrateDrop()
{
while (crateCount < 10)
{
xPos = Random.Range(10, 490);
zPos = Random.Range(10, 490);
Instantiate(crate, new Vector3(xPos, 26, zPos), Quaternion.identity);
yield return new WaitForSeconds(3);
crateCount += 1;
}
}
}
I’ve commented out what I’ve tried, but I can’t get it to work. Can anyone tell me how to make this script spawn an array of 10 types of crates randomly every 3 seconds?