Skip to content

Instantly share code, notes, and snippets.

@unitycoder
Created May 17, 2015 21:10
Show Gist options
  • Save unitycoder/dd464da0f0ffe5041e46 to your computer and use it in GitHub Desktop.
Save unitycoder/dd464da0f0ffe5041e46 to your computer and use it in GitHub Desktop.
Color fade with IEnumerator
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class ColorFader : MonoBehaviour
{
public float delay = 2;
void Start () {
StartCoroutine(Fade(delay));
}
IEnumerator Fade(float duration)
{
var comp = GetComponent<Image>();
for (float timer = 0; timer < duration; timer += Time.deltaTime)
{
//Debug.Log(timer/duration);
comp.color = Color.Lerp(Color.black,Color.clear,timer/duration);
yield return 0;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment