While Loop not working when clicked on Play button
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class GameManager : MonoBehaviour {
public List<int> randomNumbers;
private int randomNumber;
void Start()
{
RandomNumberFiller ();
}
void RandomNumberFiller()
{
while(randomNumbers.Count > 16)
{
randomNumber = Random.Range(0,16);
if(!randomNumbers.Contains(randomNumber))
{
randomNumbers.Add (randomNumber);
}
}
}
There are no errors in the script and so I clicked on Play and didn't run. I opened Task Manager and the status of Unity was 'Not Responding'. I commented the while loop and my game was working.
Please tell me what is going on.
Thanks in advance and for reading.
Your while loop is executed while your list has 16 members or more ? I think you want to fill the list up to 16 $$anonymous$$embers ? So you have to change" >" to" <"?
Thanks it worked. That was very silly. Please @TheSorm sir, add it as an answer so that I can say that it was the right answer. Well, I made the loop false in the very beginning. Thank you again sir.
Answer by srikaran_p · Jul 13, 2016 at 11:37 AM
Thanks to @MrSorm sir, I fixed this issue perfectly. I had to change the sign of greater than to lesser than in the if condition.
Your answer
Follow this Question
Related Questions
Why is this Do/While loop hanging Unity? 1 Answer
Do-While Loop not working 1 Answer
While loop causing Unity to hang up? 1 Answer