Identifying buttons in array

I’ve created an array with buttons, now I want to make some of them not interactable via script, but I don’t know how to identify them. I have something like this:

public GameObject Panel;
public Button[] buttons;

void Start () {
    buttons = Panel.GetComponentsInChildren<Button>();
}

void setbuttonsstate() {
    for (int i=1; i <= 20; i++)
    {
       if()
        {
            buttons*.interactable = false;*

}
else
{
buttons*.interactable = true;*
}
}

}
But there, I don’t know what should i put inside if(), is there any simple way to identify which button it is?

  1. You could tag them(good if you got only a few types of buttons)
  2. You could add a script to each button and have an id in it for each button(good if there are a lot of button types)

I cant think of other good ways though, I am thinking that tagging is your best bet, but if you will need to have some extra info(lifetime, color etc) about a button stored in it just have a script added to it

You can always name your buttons as you create them, then compare the name of the button with what you want it to be in the if statement.

if(buttons*.name == “someName”)*
Or you can make a random number generator to randomly pick a button to set non-interactive, it all depends on why you’re trying to set buttons non-interactive.

Each button usually have a text component. you could check the text on the button to see what button it is. for example a main menu with buttons could be something like

if (buttons*.GetComponent<Text>().Text == "Options" )*

{
buttons*.interactable = true*
}