In C#, structs are passed by value.
When you get gui.color
, you're getting a copy of the GUITexture
's color; changes made to the copy do not alter the original.
The following doesn't work, because you're modifying and discarding a copy:
gui.color.a = 0;
The following does work, because you're getting a copy, modifying it, and passing it back:
Color tempColor = gui.color;
tempColor.a = .25f;
gui.color = tmpclr;
An extension method for Color
fails for the same reason: the extension method will be called on the copy, not the original. You could write an extension method for GUITexture
, instead:
public static void SetAlpha(this GUITexture self, float alpha) {
Color tempColor = self.color;
tempColor.a = alpha;
self.color = tempColor;
}