The routine won't stop on its own because, as you said, the while loop is infinite. Instead, replace the truetrue in while(true)while(true) with a boolbool variable that you can set either inside or outside of the coroutine.
Bool allowFlicker =true While(allowFlicker) { // do stuff here
//time to stop? Then set allowFlicker false AllowFlicker = false }
bool allowFlicker =true
while(allowFlicker)
{
// do stuff here
//time to stop? Then set allowFlicker false
allowFlicker = false
}
This looks like it could also be simply placed in the updateUpdate or fixedupdateFixedUpdate functions.
typed on my phone before sleep, excuse formatting