ashayp22_Colored-Cubes/Assets/Scripts/Fade.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Fade : MonoBehaviour {

    public void Update()
    {
        StartCoroutine(FadeTextToFullAlpha(3f, GetComponent<Text>())); //fade in
    }


    //source: https://forum.unity.com/threads/fading-in-out-gui-text-with-c-solved.380822/

    public IEnumerator FadeTextToFullAlpha(float t, Text i)
    {
        i.color = new Color(i.color.r, i.color.g, i.color.b, 0);
        while (i.color.a < 1.0f)
        {
            i.color = new Color(i.color.r, i.color.g, i.color.b, i.color.a + (Time.deltaTime / t));
            yield return null;
        }
    }
}
