Question by
AhadKhan98 · Oct 11, 2016 at 04:48 PM ·
arrayarraysbuttons
How do I disable an array of Buttons?
Hi. I have created an array of Button using this code: public Button[] allObjs; I want to disable all of the buttons in the start using code. I've tried this:
case 1:
InstructionsText.text = "PRESS THE RED BUTTON";
foreach(Button obj in allObjs){
obj.GetComponent<Button> ().interactable = false;
}
However this only makes the buttons grey and not clickable. I want to completely disable them.
I tried using the Button.GetComponent().SetActive(false); method but it gives me an error stating that no gameobject found in the button. Please tell me how do I disable these buttons, Thank you.
Comment
Best Answer
Answer by AhadKhan98 · Oct 12, 2016 at 04:44 AM
I figured it out. Instead of using .GetComponent to set the gameobject to inactive. I used the code obj.gameobject.SetActive(false);
and it worked.