Created
December 24, 2018 23:13
-
-
Save AaronMeyers/6e828e1cbafe576355cf7450c4490750 to your computer and use it in GitHub Desktop.
This file contains hidden or 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; | |
| using System.Collections; | |
| using UnityEngine; | |
| public class GoFrom : MonoBehaviour | |
| { | |
| static GoFrom _instance; | |
| static GoFrom instance | |
| { | |
| get | |
| { | |
| if ( _instance == null ) | |
| { | |
| _instance = new GameObject("ZeroToOne").AddComponent<GoFrom>(); | |
| } | |
| return _instance; | |
| } | |
| } | |
| public static Coroutine ZeroToOne( float time, Action<float> tick, float delay = 0, Action finished = null ) | |
| { | |
| return instance.StartCoroutine(instance.ZeroToOneRoutine(time, tick, delay, finished)); | |
| } | |
| IEnumerator ZeroToOneRoutine( float time, Action<float> tick, float delay, Action finished ) | |
| { | |
| var timer = 0f; | |
| while ( timer < time ) | |
| { | |
| yield return null; | |
| timer += Time.deltaTime; | |
| tick.Invoke(Mathf.Clamp01(timer / time)); | |
| } | |
| if ( finished != null ) | |
| { | |
| finished.Invoke(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment