Last active
May 28, 2020 03:13
-
-
Save jfranmora/8af1f23b2cca2e18f28301e8979cdd7a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using UnityEngine; | |
/// <summary> | |
/// GC friendly coroutine utilities | |
/// @JfranMora #UnityTips | |
/// </summary> | |
public static class CoroutineUtils | |
{ | |
public static IEnumerator WaitForSeconds(float seconds) | |
{ | |
float startTime = Time.time; | |
do | |
{ | |
yield return null; | |
} while (Time.time < startTime + seconds); | |
} | |
public static IEnumerator WaitForSecondsRealtime(float seconds) | |
{ | |
float startTime = Time.realtimeSinceStartup; | |
do | |
{ | |
yield return null; | |
} while (Time.realtimeSinceStartup < startTime + seconds); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment