Disabled button

I need to show a disabled button, how can I do that?

You could have a GUITexture of a disabled button under the button you want the ability to have disabled.

When you want the GUIButton “disabled”, just stop drawing it and the GUITexture will appear.

It would certainly be quicker than playing with the GUIStyles and Skins.

Or just make its rendering inverse related to the rendering of the button.

I’d like to avoid bitmaps in place of buttons.

How can I do that?

If you are using Unity GUI rather than GUITextures, then do this:

  1. Define a GUIstyle for your disabled button. That usually means a dimmed version of the button graphic for all states.

  2. Add this to your OnGUI code to display the disabled version of the button when the appropriate condition is not met:

condition  = true; // the flag for whether the button should be active or not
if (condition) {
     if (Button ("My Button")) {
          // do button stuff
     }
} else {
     Button ("My Button", "button_disabled"); // display with the disabled button style and don't respond to the button press
}

You can always set GUI.enabled to false for the button, which fades it out and makes it inoperable.

–Eric

Thanks Eric, that’s much cleaner! (We implemented our solution possibly before GUI.enabled was introduced, but I’m not totally sure about that.)

Thanks! That’s what I was looking for.