- Home /
Enabling loop and disabling loop
Hi!
I have a small project I am working on and I want to know how I can activate a loop and then disable it after a few seconds. If you know, please tell me.
Thanks
I also made some code that works but does not disable the loop.
function HarlemShake () {
yield WaitForSeconds(15.18);
harlemEnabled = true;
while(harlemEnabled == true){
yield WaitForSeconds(0.1);
camera.backgroundColor = Color.magenta;
yield WaitForSeconds(0.1);
camera.backgroundColor = Color.yellow;
yield WaitForSeconds(0.1);
camera.backgroundColor = Color.red;
yield WaitForSeconds(0.1);
camera.backgroundColor = Color.green;
yield WaitForSeconds(0.1);
camera.backgroundColor = Color.blue;
yield WaitForSeconds(0.1);
camera.backgroundColor = Color.white;
}
yield WaitForSeconds(14.08);
harlemEnabled = false;
}
Comment
Answer by coah · Feb 11, 2014 at 08:47 PM
You never go out of the loop, you need to break the loop at some point.
I would probably do something like this,
while( true ){
camera.backgroundColor = colorArr[i];
i++;
if( i == colorArr.Length ){ i=0; }
yield WaitForSeconds( delay );
time += delay;
if( time >= maxTime ){ break; }
}
Your answer
Follow this Question
Related Questions
Disable an child object 1 Answer
Help With Disabling/Enabling single GameObject 1 Answer
Disable gun if it is not mine? 1 Answer
Enable/Disable shader on script 2 Answers
Script Not staying disabled 2 Answers