- Home /
 
UI Toolkit, Gray out a button using a second button
I have been using UI Toolkit for a while now so I'm pretty familiar with how it works in Unity. What I am trying to do is have a button "deactivate" another button when pushed. I would like the second button to turn gray when the first button is pushed and not do anything. Inversely, I would also like to have a third button "reactivate" the second button.
Button 1- deactivates Button 2. Button 2- normal operation until deactivated by Button 1 and undergoes a state change to gray. Button 3- reactivates Button 2 to normal operation and makes state change of Button 2 back to normal.
Here's a chunk of the code:
 void Start () 
 {
     
     SetupButtons();    
     
 }
 
 void SetupButtons()
 {
     var Button1 = UIButton.create ("Button1UP.png", "Button1DOWN.png", 0, 0);
     Button1.positionFromBottomLeft(pos,pos);
     Button1.centerize();
     Button1.highlightedTouchOffsets = new UIEdgeOffsets(10);
     
     var Button2 = UIButton.create ("Button2UP.png", "Button2DOWN.png", 0, 0);
     Button2.positionFromBottomLeft(pos2,pos2);
     Button2.centerize();
     Button2.highlightedTouchOffsets = new UIEdgeOffsets(10);
     Button2.onTouchUpInside += sender => Debug.Log ("Hit button 2");
     //Button2.onTouchUpInside += sender => 
     
     var ResetButton = UIButton.create ("ResetUP.png", "ResetDOWN.png", 0, 0);
     ResetButton.positionFromBottomLeft(pos3,pos3);
     ResetButton.centerize();
     ResetButton.highlightedTouchOffsets = new UIEdgeOffsets(10);
 }
 
              Answer by shockreel · May 10, 2013 at 05:40 PM
Solved. I created a second "gray" button below the buttons to be grayed out and used '.hidden' to hide the active button above.
Your answer