Turn single script into three seperate actions (mouse clicks)

I have 3 separate boxes (transforms) and a button that when clicked with the mouse checks to see if box one is empty? if it is… it places an object in the box, if box one if full it checks / places an object in box two… and box three and so on…

How can I make it so the checking & filling of each box is done by a separate mouse click (at the moment all boxes are checked / filled by a single click)

 public GameObject newItem;
    public Transform[] Slots;
    public bool Slot1 = false; //false = empty, true = not empty
    public bool Slot2 = false;
    public bool Slot3 = false;


    void OnMouseDown()
    {
        if(Slot1 == false)
        {
            Instantiate(newItem, Slots[0].position, Slots[0].rotation); //place item in 1st slot
            Slot1 = true; //slot 1 now full
        }
        else if(Slot1 == true)
        {
            //Do Nothing !
        }

        if (Slot1 == true && Slot2 == false)
        {
            Instantiate(newItem, Slots[1].position, Slots[1].rotation); //place item in 2nd slot
            Slot2 = true; //slot 2 now full
        }
        else if (Slot2 == true)
        {
            //Do Nothing !
        }

        if (Slot1 == true && Slot2 == true && Slot3 == false)
        {
            Instantiate(newItem, Slots[2].position, Slots[2].rotation); //place item in 3rd slot
            Slot2 = true; //slot 3 now full
        }
        else if (Slot3 == true)
        {
            //Do Nothing !
        }
    }

All help greatly appreciated !

hi;

I give u a simple optimized example :

 public GameObject newItem;
    public Transform[] Slots;
    public bool[] slotCheck; //false = empty, true = not empty
  


    void OnMouseDown()
    {

        for (int i = 0; i < Slots.Length; i++)
        {
            if (slotCheck *== false)*

{
Instantiate(newItem, Slots_.position, Slots*.rotation); //place item in 1st slot*
slotCheck = true;
break;_

}
}

}
but your script is not well optimized u are not using any arrays so it makes your script complicated;
i change the slot variable to be like an array ;
so change its length in the editor just to be like Slots variable witch is transform;
then i created a loop and check for each one and used " break " so each time if it check it will break the function and dont check the others so u have to click another time;

Okay. Your code does a little more than it seemed like your textual explanation stated. There is a dependency between slots. Some of those dependencies are redundant. Like Slot3 depends on both Slot2 and Slot1 but Slot2 already depends on Slot1.

Here’s some code that I’m guessing fulfills your intent…

using UnityEngine;

public class Slot : MonoBehaviour
{
  public GameObject NewItem;
  public Slot[] Dependencies;
  public Transform Container;
  public bool Filled = false; //false = empty, true = not empty

  void OnMouseDown()
  {
    foreach (var dependency in Dependencies)
      if (!dependency.Filled) return;

    if (Filled) return;

    Instantiate(NewItem, Container.position, Container.rotation);
    Filled = true;
  }
}

You then configure it by dragging in the dependencies.