Fading alpha of quad with unlit alpha texture

Having some difficulty changing alpha over time (deltatime of Update) on a quad that has a texture (icon) applied via Unlit texture with alpha (png)

Basically this:

public float _maxtime = 2.0f;
private float timer = 0.0f;
private Color colorAlpha; // fade amount for interaction icons

void Start () {
        colorAlpha = footIcon.GetComponent<Renderer>().material.color;
    }

void Update () {
timer += Time.deltaTime;
// set icon fade to reflect how long it has been looked at
colorAlpha.a =  Mathf.Min (timer/_maxtime + 0.5f, 1.0f);
footIcon.GetComponent<Renderer>().material.color = colorAlpha;

}

This doesn’t appear to do anything. Is there a separate way I have to call to change alpha on the texture image (icon.png) itself?

Besides that you should cache the Renderer component so you do not need to look it up each frame the code should work.
Make sure you have a shader that support Transparency via the Main color.
The Unity Unlit shader do not have a variant with A texture + Transparency via the color attribute.
This shader from the unity wiki should work fine for you.

http://wiki.unity3d.com/index.php/UnlitAlphaWithFade

Shader "Unlit/UnlitAlphaWithFade"
{
    Properties
    {
        _Color ("Color Tint", Color) = (1,1,1,1)   
        _MainTex ("Base (RGB) Alpha (A)", 2D) = "white"
    }

    Category
    {
        Lighting Off
        ZWrite Off
                //ZWrite On  // uncomment if you have problems like the sprite disappear in some rotations.
        Cull back
        Blend SrcAlpha OneMinusSrcAlpha
                //AlphaTest Greater 0.001  // uncomment if you have problems like the sprites or 3d text have white quads instead of alpha pixels.
        Tags {Queue=Transparent}

        SubShader
        {

                   Pass
                   {
                        SetTexture [_MainTex]
                        {
                    ConstantColor [_Color]
                               Combine Texture * constant
                }
            }
        }
    }
}
1 Like

Awesome, thank you so much for the help!

Hmm, tried it out, but will have to either keep looking, or learn more about shaders (so handy, yet my weakest skill when it comes to all of this…); the problem is that my icon is a .png with alpha layer/color, so that needs to be transparent (in addition to being able to change the overall alpha); doesn’t seem to work that way with the above shader

Maybe if I research enough about shader programming I can make it work (I hope)

If the GameObject is a UI image you need to use () not ().

And I see I’m 2 years late with my reply.