WaitForRealSeconds ? [SOLVED]

How does one go about creating their own implementation of YieldInstruction? I browsed the coroutine classes in MonoDevelop, but couldn’t find anything in the object browser that could hint me into what are the requirements.

I was just interested in creating my own version of WaitForSeconds, like WaitForRealSeconds one that uses Time.realtimeSinceStartup instead.

I’m not sure it’s possible to implement your own YieldInstruction, as this class is completely undocumented.

However, it is possible to construct something with equivalent behavior by using the Coroutine returned by StartCoroutine (untested):

public Coroutine WaitForRealSeconds(float time)
{
    return StartCoroutine(WaitForRealSecondsImpl(time));
}

private IEnumerator WaitForRealSecondsImpl(float time)
{
    float startTime = Time.realtimeSinceStartup;
    while (Time.realtimeSinceStartup - startTime < time)
        yield return 1;
}

// use without 'new':
yield return WaitForRealSeconds(5);

This is perfect. Have to admit it took me second to understand what was going on.

This case is solved.

Time.realtimeSinceStartup wouldn’t fit running on unity-instance dedicated servers, because after running for 1.5 days, the float time precision will be down to 0.1 seconds, then to 1 second after running for 2 weeks, which might lead to a disaster. Correct me if i’m wrong.
How about Network.time ?