- Home /
while Looping
I making a gui animation. I have a four Texture2D , looping this textures. This Script Loop and stoping Unity3d.
var num:int=0;
function Update () {
while (num<=4) {
num++;
Debug.Log(num);
if(num==4){
num=0;
}
}
}
Check your logic. When num reaches 4 it is set to 0 before the while evaluation, resulting in an infinite loop.
Answer by GC1983 · Jan 25, 2012 at 06:46 PM
Maybe you shouldnt use a while loop. Just a if statement. The Update() is pretty much a loop in its own if you manipulate it properly. So try:
function Update(){
if(num
num++;
if(num >= 4) num = 0; } }
With this, it will increment the variable as long as the if statement is true and may not crash your game.
Your answer

Follow this Question
Related Questions
How to use a WHILE LOOP? Obviously not inside ***function Update*** 3 Answers
While loop issues in Update() vs. Start() 0 Answers
Changing a boolean value on button press not acting as expected? 1 Answer
How do I Instantiate a prefab to touch and still update a score? 1 Answer
Is there a scene setup call or update for editor scripts? 3 Answers