How can i only get the object clicked once?

Hello I`m using a collider for my Shop and i have a problem that if you hold clicked it is buying unlimited times. But i wanna have only one buy per Click

Heres my Script

                if (hit2.collider.name == "Item2")
                {
                    if (Infected >= item2numberprice)
                    {
                        if (item2bought <= item2max)
                        {
                            while (x == 0)
                            {
                                Infected -= item2numberprice;
                                item2bought = 1;
                                item2boughttimes += 1;
                                x += 1;
                                break;
                            }
                        }
                    }
                }

                x = 0;

The problem is probably just outside the code you posted. Are you using a OnTriggerEnter or an OnTriggerStay?

Im using this:

       if (Input.GetMouseButton(0))
        {
            Ray ray2 = cam.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit2;

            if(Physics.Raycast(ray2, out hit2))

Same problem tho: you are continously executing your code as long as the key is pressed.
Instead use GetMouseButtonDown(0), which is only true for the first frame in which the button was pressed.

Worked Thank you