Hi! I have a problem with some scenes in my project. When I start the game Unity freezes and I have to force the quit to close Unity process (Note that this does not always happen and the game starts properly!). After many attempts I discovered that maybe the problem is a series of while loops in my C# script (in fact removing them from the code, the game seems to start always without problems).
I have a vector with nine numbers in my Start() class. Than I take a random number from the vector and I save it in a new variable, and so on for eight times.
But I don’t want that the same number can be stored in two or more different variables, so I wrote this code that contein the while loops. I hope someone can help me fix it so it will work without crashing unity.
int[] array = { number1, number2, number3, number4, number5, number6, number7, number8, number9 };
insidearray1 = array[Random.Range(0, 8)];
for(int i = 0; i < 9; i++)
{
if (array *== insidearray1)*
-
{*
_ array = 0;_
* break;*
* }*
* }*
* insidearray2 = array[Random.Range(0, 8)];*
* while (insidearray2 == 0)*
* {*
* insidearray2 = array[Random.Range(0, 8)];*
* }*
* for(int i2 = 0; i2 < 9; i2++)*
* {*
* if (array[i2] == insidearray2)*
* {*
* array[i2] = 0;*
* break;*
* }*
* }*
* insidearray3 = array[Random.Range(0, 8)];*
* while (insidearray3 == 0)*
* {*
* insidearray3 = array[Random.Range(0, 8)];*
* }*
* for(int i3 = 0; i3 < 9; i3++)*
* {*
* if (array[i3] == insidearray3)*
* {*
* array[i3] = 0;*
* break;*
* }*
* }*
And so on… (All thi is inside the Start() class). Thanks!