Conditionals in UI Drag and Drop?

Hi,
I have a nice UI drag and drop system (big thanks to quill18 and BoredMormon for their tutorials) and want to get some conditionals in it.
I have 4 numbers (that are instantiated on the canvas) that I can to drag and drop on 4 specific dropzones.
The numbers return to their original position if they’re not dropped on the specific dropzone.

Here’s the Drag script:

public class Drag : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler {	
	public Vector3 			positionToReturnTo;

	public enum 			Slot { ONE, TWO, THREE, FOUR};
	public Slot				typeOfItem = Slot.ONE;

	public void OnBeginDrag(PointerEventData eventData){
		positionToReturnTo = this.transform.position;
		GetComponent<CanvasGroup> ().blocksRaycasts = false;
		Debug.Log ("OnBeginDrag");
	}

	public void OnDrag(PointerEventData eventData){
		this.transform.position = eventData.position;
		Debug.Log ("OnDrag");
	}

	public void OnEndDrag(PointerEventData eventData){
		GetComponent<CanvasGroup> ().blocksRaycasts = true;
		this.transform.position = positionToReturnTo;
		Debug.Log ("OnEndDrag");
	}		
}  

Here is the Dropzone script:

public class Dropzone : MonoBehaviour, IDropHandler {

	public Drag.Slot 	typeOfItem = Drag.Slot.ONE;

	public void OnDrop (PointerEventData eventData)
	{
		Debug.Log (eventData.pointerDrag.name + "was dropped on " + gameObject.name);

		Drag d = eventData.pointerDrag.GetComponent<Drag> ();
		if (d != null) {
			if (typeOfItem == d.typeOfItem) {
				d.positionToReturnTo = this.transform.position;
			}		

		}
	}
}

The logic I want to put in is:

  • First numberOne needs to be placed on dropzoneOne
  • Only then numberTwo can be placed on dropzoneTwo
  • Only then numberThree can be placed on dropzoneThree
  • Only then numberFour can be placed on dropzoneFour

I tried here below with bools but it doesn’t work. Can anybody help me?
EDIT:
further information:

Only case “one” does work: numberTwo, numberThree and numberFour bounce back to their original positions before I drop numberOne on dropzoneOne.
The bool oneInDropzone is also set to true.

After that: numberTwo, numberThree and numberFour keep bouncing back to their original positions when I drag and drop them.
So it stops at case “two”, I can’t drop numberTwo on dropzoneTwo.

I made the bools public and in play mode I see that oneInDropzone = true in the Dropzone script on dropzoneOne, but I don’t see the change on dropZoneTwo,dropZoneThree,dropZoneFour. They all have the same script, how is that possible?

public class Dropzone : MonoBehaviour, IDropHandler {

	public Drag.Slot 	typeOfItem = Drag.Slot.ONE;

	bool 				oneInDropzone = false; 
	bool 				twoInDropzone = false; 
	bool 				threeInDropzone = false; 


	public void OnDrop (PointerEventData eventData) {
		Debug.Log (eventData.pointerDrag.name + "was dropped on " + gameObject.name);

		Drag d = eventData.pointerDrag.GetComponent<Drag> ();
		if (d != null) {
			if (typeOfItem == d.typeOfItem) {
				switch (eventData.pointerDrag.tag) {
				case "one":
					d.positionToReturnTo = this.transform.position;
					oneInDropzone = true;
					break;
				case "two":
					if (oneInDropzone == true) {
						d.positionToReturnTo = this.transform.position;
						twoInDropzone = true;
					}
					break;
				case "three":
					if (twoInDropzone == true) {
						d.positionToReturnTo = this.transform.position;
						threeInDropzone = true;
					}
					break;
				case "four":
					if (threeInDropzone == true) {
						d.positionToReturnTo = this.transform.position;
					}
					break;
				}
			}
				
		}

	}

}

the problem is: you have seperate drop zones for the different dragables. setting the boolean for “ONE” to true, for one dropzone does not set it to true for each dropzone

a quick solution should be to make the boolean variables static.

i would not recommend this solution, btw. I’d change the drag-drop system to fit better into my game.