How to Change the Alpha of a Material In Code

Sup everyone,

I have a loading screen in my game which I want to fade out when I tell it to. I started by making an object for which I attached a material. I changed the rendering mode to fade and by changing the alpha in the Albedo section I can get a variable alpha manually.

My question comes to changing it in the code. I’ve been doing the following:

public Material myMaterial;
public float alphaChange = 255;

void Update()
{
    alphaChange -= 50;

    if (alphaChange < 0)
    {
        alphaChange = 0
    }

    myMaterial.color = new Color(0, 0, 0, alphaChange);
}

This has not worked at all. How am I supposed to change the alpha?

    public Material myMaterial;
    public float alphaChange = 1.0f;
    
    void Update()
    {       
        if (alphaChange > 0)
            alphaChange -= 0.01f;
    
        myMaterial.color = new Color(0, 0, 0, alphaChange);
    }

Oh!!! So you use the 0 to 1 in the code. Not 0 to 255. Thanks zulo3d!

yeah the 255 is for Color32, Color uses 0.0-1.0.

As far as I tried, modifying a Color32 doesn’t work, but Color always works just fine