- Home /
Blinking loop of images? Half-done...
I got an array where I store the name of the image (draw with GUI.DrawTexture). I do the blinking with this and works perfect:
if(Time.time % 2 < 1) { blink = true; }
else { blink = false; }
But, I need to show X seconds (lets say, 4) the first image from the array, another 4 seconds the second image, and so on. And when I reach the limit of the array, start again. I have a function that's called on OnGUI with this code, but it doesn't work fine:
if(blink == true) {
if(lineCounter <= lineNumber.length) {
GUI.DrawTexture(Rect(Screen.width/2 - 406, Screen.height /2 - 180, 811, 360), Resources.Load("line" + lineNumber[lineCounter].ToString()), ScaleMode.StretchToFill, true, 0);
yield WaitForSeconds(4);
lineCounter++;
}
}
if(lineCounter > lineNumber) { lineCounter = 0; }
What I'm doing wrong?
Answer by Berenger · Feb 21, 2012 at 03:43 AM
Call that outside of OnGUI, and only once.
function Start(){
Blink();
}
function Blink(){
lineCounter = 0;
while( lineCounter < lineNumber ){
tex = Resources.Load("line" + lineNumber[lineCounter++].ToString());
yield WaitForSeconds( 4 );
}
}
OnGUI()
...
GUI.DrawTexture(..., tex) ;
You were creating a new coroutine each GUI loop, displaying the the texture once and waiting 4 seconds, which means lineCounter is increased for the first time after 4 seconds, then immediatly increased multiple time as all the coroutines finish.
That works perfect! And thanks for the explanation of my error! Now I can use that on other things! :)
Your answer
![](https://koobas.hobune.stream/wayback/20220613064255im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Drawing a GUI.DrawTexture call above GUI.Button in seperate scripts 0 Answers
DrawTexture without stretching it 0 Answers
GUI.DrawTexture isn't centred. Help? 1 Answer
GUI.DrawTexture disable anti alias 1 Answer
Another GUI question. HealthBar 1 Answer