Created
May 17, 2015 21:10
-
-
Save unitycoder/dd464da0f0ffe5041e46 to your computer and use it in GitHub Desktop.
Color fade with IEnumerator
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
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