Created
December 1, 2020 18:20
-
-
Save PreyK/e768c6bec2d70e85a6e9da299370bc56 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
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