Skip to content

Instantly share code, notes, and snippets.

@AaronMeyers
Created December 24, 2018 23:13
Show Gist options
  • Select an option

  • Save AaronMeyers/6e828e1cbafe576355cf7450c4490750 to your computer and use it in GitHub Desktop.

Select an option

Save AaronMeyers/6e828e1cbafe576355cf7450c4490750 to your computer and use it in GitHub Desktop.
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