Quantcast
Channel: Questions in topic: "crash"
Viewing all articles
Browse latest Browse all 2383

Editor Freezes on Play

$
0
0
While prototyping I came up with an issue. When I try to use a coroutine (also tried it while) Unity crashes. The cause is infinite loop, however as you will understand from the code it is something intended: public GameObject[] enemies; //Game Manager public GameManager gameManager; //Frequency int counterMax = 45; int count = 0; // Use this for initialization void Start () { } void Update() { //If playing if (gameManager.isPlaying) { //Increase the count count += 1; //When count reaches the max count if(count == counterMax) { //Spawn the enemy Spawn(); //Reset the counter count = 0; } } } void Spawn() { //While playing while (gameManager.isPlaying) { //Pic a random enemy int i = Random.Range(0, enemies.Length); //INstantiate the enemy Instantiate(enemies[i], transform.position, Quaternion.identity); } } This is the latest code I tried, the idea is to set isPlaying false when game ends. Am I missing a point?

Viewing all articles
Browse latest Browse all 2383

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>