Skip to content

Instantly share code, notes, and snippets.

@unitycoder
Created May 17, 2015 21:10
Show Gist options
  • Select an option

  • Save unitycoder/dd464da0f0ffe5041e46 to your computer and use it in GitHub Desktop.

Select an option

Save unitycoder/dd464da0f0ffe5041e46 to your computer and use it in GitHub Desktop.

Revisions

  1. unitycoder revised this gist May 17, 2015. 1 changed file with 0 additions and 8 deletions.
    8 changes: 0 additions & 8 deletions ColorFader.cs
    Original file line number Diff line number Diff line change
    @@ -4,14 +4,8 @@

    public class ColorFader : MonoBehaviour
    {

    public float delay = 2;

    void Awake()
    {
    GetComponent<Image>().enabled = true;
    }

    void Start () {
    StartCoroutine(Fade(delay));
    }
    @@ -25,8 +19,6 @@ IEnumerator Fade(float duration)
    comp.color = Color.Lerp(Color.black,Color.clear,timer/duration);
    yield return 0;
    }

    gameObject.SetActive(false);
    }

    }
  2. unitycoder created this gist May 17, 2015.
    32 changes: 32 additions & 0 deletions ColorFader.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI;

    public class ColorFader : MonoBehaviour
    {

    public float delay = 2;

    void Awake()
    {
    GetComponent<Image>().enabled = true;
    }

    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;
    }

    gameObject.SetActive(false);
    }

    }