Wanting make a shop system. I am stuck with script to make a button not to click again once click.

Hello, I am trying to make a shop sysem for my game. I am stuck with these lines of code. I want to make a button to buy something but after I bought, I don’t want to buy it again. How can I do that with these code? I think that I should use boolean but I couldn’t. By the way, index is coming from which rocket has choosed. Thank you for your help.

public void BuyButton()
        {
        
            switch (index)
            {
                case 0:
                    if (//Item has not sold)
                    {
                        moneyAmount -= firstMoneyOfRocket;
                        PlayerPrefs.SetFloat("Cash", moneyAmount);                
                    }  
                    else if (//Item sold)
                    {
                        Debug.Log("You already bought this item.");
                    }
                    break;
                case 1:
                    if(//Item hasnt sold)
                    {
                        moneyAmount -= secondMoneyOfRocket;
                        PlayerPrefs.SetFloat("Cash", moneyAmount);
                    }
                    else if (//ItemSold)
                    {
                        Debug.Log("You already bought this item.");
                    }
                
                    break;
            }
        }

If you post a code snippet, ALWAYS USE CODE TAGS:

How to use code tags: Using code tags properly

Generally, separate processing of the button click itself (the “intent”) from doing the work (the “action”).

  • always gather the click of the button

  • if you CAN do it (logic located far away from the button), then do the action

  • if you cannot do it, then don’t do it, or perhaps make a different sound

Once you have that working, then you can easily make something else to control this field on the button: