I think this should do the trick:
public class SetAlpha : MonoBehaviour
{
public Material materialWithAlphaValue;
public void ChangeAlphaValue(Color color)
{
materialWithAlphaValue.SetColor("_MY_COLOR_SHADER_VARIABLE_NAME", color);
}
}
UPDATE:
public class SetAlpha : MonoBehaviour
{
public Material materialWithAlphaValue;
public void ChangeAlphaValue(float alpha)
{
var color = materialWithAlphaValue.GetColor("_MY_COLOR_SHADER_VARIABLE_NAME");
materialWithAlphaValue.SetColor("_MY_COLOR_SHADER_VARIABLE_NAME", new Color(color.r, color.g, color.b, alpha));
}
}
UPDATE 2:
Using Material.Color is the same as using Material.GetColor("_Color"); this is the default naming for base colors in the standard unity shaders.
public void ChangeDefaultMatAlpha(float a)
{
_MyMaterial.color = new Color(_MyMaterial.color.r, _MyMaterial.color.g _MyMaterial.color.b,
a);
}
sharedMaterialandMaterial Property Blocks, they help you changing the attributes of your material, which will reflect in the shader.Tags {"Queue"="Transparent" "RenderType"="Transparent" }) and to set the correct blend type (Blend SrcAlpha OneMinusSrcAlpha), otherwise your alpha won't make a difference.