I want to change the alpha value of an existing color. However, I cannot directly edit the color.
When I try something like this:
gui.color.a = 0;
I get the following error:
Error: Cannot modify the return value of 'UnityEngine.GUITexture.color' because it is not a variable.
But if I copy the variable I am able to edit the alpha value.
Color tempColor = gui.color;
tempColor .a = .25f;
gui.color = tmpclr;
Why is this? Why is the new instance of the Color not throwing the same error?
Additionally, I thought that because I had to do this often I would write a little extension method like this:
private static Color tempColor;
public static void SetAlpha(this Color color, float alpha)
{
tempColor = color;
tempColor.a = alpha;
color = tempColor;
}
But to my surprise this compiled but didn't change the alpha value at all. Can anyone explain why this might not be working?