Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

fade image out unity

IEnumerator FadeImage(bool fadeAway)
{
    // fade from opaque to transparent
    if (fadeAway)
    {
        // loop over 1 second backwards
        for (float i = 1; i >= 0; i -= Time.deltaTime)
        {
            // set color with i as alpha
            img.color = new Color(1, 1, 1, i);
            yield return null;
        }
    }
    // fade from transparent to opaque
    else
    {
        // loop over 1 second
        for (float i = 0; i <= 1; i += Time.deltaTime)
        {
            // set color with i as alpha
            img.color = new Color(1, 1, 1, i);
            yield return null;
        }
    }
}
 
PREVIOUS NEXT
Tagged: #fade #image #unity
ADD COMMENT
Topic
Name
6+1 =