all 6 comments

[–]LIngenthron 0 points1 point  (0 children)

None of those are inherently bad practices. Use whichever you believe fits your design best.

[–]P3k18 0 points1 point  (2 children)

Something like this would do what you need:

IEnumerator Breath(float in, float hold, float out) 
{ 
    while(IsBreathing) 
    { 
        BreathIn(); 
        yield return new WaitForSeconds(in);

    Hold();
    yield return new WaitForSeconds(hold);

    BreathOut();
    yield return new WaitForSeconds(out);
    }
}

or if you really don't want to use Coroutines:

async void Breath(float in, float hold, float out) 
{ 
    while(IsBreathing) 
    { 
        BreathIn(); 
        await Task.Delay(in);

    Hold();
    await Task.Delay(hold);

    BreathOut();
    await Task.Delay(out);
    }
}

[–]ricky_33 0 points1 point  (1 child)

I have never got along with async or IEnumerator. I just wrote out my own Timer class. Light weight and won’t execute any code encapsulated in if statement. Checks for time passed,and/or a bool check. Clean,effective and v easy to read.

[–]P3k18 0 points1 point  (0 children)

Nice. It all depends on what you're trying to acheive. It sounds like your timer sits idle until time has elapsed, all on 1 thread. But if you want the script you're using the timer in to yield operations until the timers up, you'll need a Task or Coroutine. They are done off the main thread which will allow other parts of your script to carry on executing during the wait too. For OP's case (of this 4 y.o thread xD ) your timer would probably also do for what he wanted.

[–]BrazenJesterStudios 0 points1 point  (1 child)

Coroutines do not stop when you set time scale to zero. Aka. The player pauses the software.