How do I enable and disable multiple buttons on button a click?,How can i disable multiple buttons with the click of one button and re-enable them with a click of another?

I have buttons in the scene that show different panels. Then a close button on the panels. I want to disable all of the buttons when a panel is shown so the user cannot open multiple panels. Then on closing the panel enable the buttons again. I figured out how to do it through the On click() event in he inspector but I have to add the disable for each button on each button and do the same for the the close button of each panel. Seems like there should be a script that could get all of them and do it. O even if I had to add them all to the script it is still better than adding all the buttons one at a time on each button.
Hope this makes sense.

@gwinnc You can keep all the buttons in a panel(say buttonPanel) and on press of the buttons:

    Button []btns = buttonPanel.gameObject.GetComponentsInChildren<Button >();
    foreach (Button btn in btns)
        btn.enabled = false;

Thank you for your help. I tried the below code but I get an error “Then name ‘buttonPanel’ does not exist in the current context.”
I created a panel and named it buttonPanel and added my buttons inside that panel. When I try to add the script to the button I get the error.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class DiableButton : MonoBehaviour {
public void DisableButtons(){
Button btns = buttonPanel.gameObject.GetComponents();
foreach (Button btn in btns)
btn.enabled = false;
}
}
@Priyanka-Rajwanshi

Hello there,

Have you tried using a Canvas Group? If you set a Canvas Group’s interactable to false, then all of its button children will become non-interactable as well. And then you can set it back to interactable again.

You can also use Canvas Groups’s Alpha property to fade in/out entire panels at a time. Pretty neat stuff.


I hope that helps!

~Cheers,

LegendBacon

@Legend_Bacon
This did disable the buttons. However I have an animation on the buttons when the are pointed at the button gets bigger and has some test appear. The animation increases the size of all the buttons in the canvas group until I close the panel. Then the animation on the previously selected button picks up in the middle. Seems like a good idea but I ma not sure why it animates all the buttons i the group when I am just changing the interactable setting.