Home > OS >  Having trouble changing material alpha color in Unity
Having trouble changing material alpha color in Unity

Time:11-15

I'm trying to change a material alpha colour on runtime, but it isn't working.

Here is my script that changes the colour:

    public Material materialCol;
    public Color color;
    void Start()
    {
        color.a = PlayerTalents.talents_.sight;
        materialCol.SetColor("_Color",color);
    }

"color" is just white with alpha set to max

Here is the material setup:

material set up

Here is what it looks like in-game:

in-game

Here are the material properties of albedo in-game:

material properties

CodePudding user response:

Make sure the value of PlayerTalents.talents_.sight is between 0 and 1f. I've tested the code, this works:

using UnityEngine;
public class AlphaTest : MonoBehaviour
{
    public Material materialCol;
    public Color color;
    void Start()
    {
        color.a = 0.7f;
        materialCol.SetColor("_Color", color);
    }
}

enter image description here enter image description here

  • Related