Elements Opacity(GUI)[SOLVED]

Hello everyone, i came here to know how to set a opacity in the elements of my GUI.

I’ve tried this, but with no success:

var opa = 0.5f;
GUI.color.a = opa;

Inside of one OnGUI function, but i’ve received this error on console:
“error CS1612: Cannot modify a value type return value of `UnityEngine.GUI.color’. Consider storing the value in a temporary variable.”

But then i realized, i’m storing a value inside of a temporary variable, like opa. How to solve that, and if i’m in the wrong way to set opacity please set me on trails.

Thank you.

1 Answer

1

Try this:

Color color = GUI.color;
color.a = 0.5f;
GUI.color = color;

The error is because you were trying to modify the alpha value directly.

Thank you! if I want to make the buttons appear slowly and one after another, as I do?

–

To fade over time, you will need to change the alpha over time. If Do a Google search for "Unity3d GUI fade", and you will find a number of different answers on this issue, many with source. Try out some of the examples. If you get stuck, post a new question with the source you've done so far.

–

i'll do that, thanks.

–