Hi,I am trying to create a crossword game with 36 buttons with alphabets on them. I want to be able to disable any of these buttons individually when I click on them but I dont know how to achieve this.
Remember that much of graphics rendering takes place as a state machine… To disable a GUI button, set GUI.enabled = false
just before drawing it, then set GUI.enabled = true
right afterwards to re-enable other controls that get drawn after the disabled button.
See documentation for more information.
→ Unity - Scripting API: GUI.enabled
All controls drawn with GUI.enabled = false
will be grayed out and inoperable.
Update with code sample. I had to fill the string
with the characters with periods, because I don’t know which alphabet has 36 letters. The english one only has 26. Hopefully you get the point.
Boolean[] BtnEnabled = new Boolean[36];
string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ..........";
void OnGUI ()
{
for( int i=0 ; i<36 ; i++ )
{
GUI.enabled = BtnEnabled;
if( GUILayout.Button(alphabet) )
{
_BtnEnabled = false;
}
GUI.enabled = true;
}
}
I asked a similar question before. I didn’t get a perfect solution in here. But I might provide some info that might be helpful.