How to make object active/non-active with coroutine + while loop

I’m just starting here… I want to make the object appear and disappear every 1sec using coroutine and in a endless while loop. I can make it appear and disappear but I don’t know how to make it endless with while loop.

I bet it’s simple but any advice for a beginner? Where do we go from here

Your logic has a tiny flaw in it. At the end of your while loop, you’re immediately resuming at the top of the while loop. You only “wait” at the yield statement. So after the yield you turn the object off but you immediately turn it back on within the same frame since the coroutine will run from yield to the next yield. If you want to turn it on / off with a delay in between, you need two yields. So you need another one after setting it to false before you set it back to true.

I bet my logics have many flaws but thanks for help! :slight_smile: I added one more yield line and it works now. Like I said “I bet it’s simple” and that’s what it was. Thanks.

1 Like