So maybe I’m missing something extremely nooby, but I can’t figure out why this is freezing the client… the idea is to spawn up to 20, and each time one is destroyed, spawn a new one.
public class spawnNew : MonoBehaviour {
public int CoinsCount = 20;
public GameObject Coins;
public float spawnArea = 20.0F;
void Update () {
GameObject[] countObj;
countObj = GameObject.FindGameObjectsWithTag ("Collect");
print (countObj.Length);
while (countObj.Length < CoinsCount) {
Vector3 spawnCoord = new Vector3(Random.Range(-spawnArea, spawnArea), 0, Random.Range(-spawnArea, spawnArea));
Instantiate(Coins, spawnCoord, Quaternion.identity);
}
}
}
Edit: Thank you for all the answers, I cannot upvote everyone as I’m still rather new but I appreciate it! Sometimes it’s easy to get stuck in two different ‘loops’ and forget the core one isn’t being updated =)
I switched from a while i< and had i++ at the bottom and forgot to update the countObj!