OnClick method how to make the button non-interactable via code?

I have the script on GameManager which affects various similar buttons. I want the button to be interactable=false when the onclick event runs.

I can’t have another onclick event because it’s gonna be an if statement. How can I do that?

Don’t know what this part means. Generally a single event can trigger a bunch of different things if you want.

But ultimately, you’re going to have some code that runs when the button is clicked, and that code needs to include a line that sets interactable to false for that button.

1 Like

So I did it with

    public Button[] WeaponButton;
    public void isMoneyEnoughForWeapons()
    {
        for (int i = 0; i < weapons.Length; i++)
        {
            Weapon = weapons[i];
            if (money < Weapon.weaponPrice)
            {
                WeaponButton[i].interactable = false;
            }
            else if(ownedWeapon[i] == false)
            {
                WeaponButton[i].interactable = true;

            }
        }

I just want to know if there is something simpler; cause this needs to be updated from inspector when I add another button.

Any solution is going to involve somehow making a list of which button corresponds to which weapon, so that you can check the appropriate price.

However, you might find it more convenient to create just a single button in your scene, and then have your script make copies of it for each weapon. You’d still need a list of weapons, but the buttons could be updated automatically. The downside is that anything unique about a particular button (like its graphic, label, or position) needs to somehow be controlled from code instead of being set manually.

Alright let’s see how I can do that. Thank you for the response.