Skip to content

Instantly share code, notes, and snippets.

@PreyK
Created December 1, 2020 18:20
Show Gist options
  • Save PreyK/e768c6bec2d70e85a6e9da299370bc56 to your computer and use it in GitHub Desktop.
Save PreyK/e768c6bec2d70e85a6e9da299370bc56 to your computer and use it in GitHub Desktop.
public static Coroutine StartTimer01(this MonoBehaviour mb, float exitTime, Action onFinished, Action<float> onUpdate)
{
return mb.StartCoroutine(Timer01(exitTime, onFinished, onUpdate));
}
public static IEnumerator Timer01(float exitTime, Action onFinished, Action<float> onUpdate)
{
float journey = 0f;
while (journey <= exitTime)
{
journey = journey + Time.deltaTime;
float percent = Mathf.Clamp01(journey / exitTime);
onUpdate.Invoke(percent);
yield return null;
}
onFinished.Invoke();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment