Question by
MrAsterB · Feb 05, 2020 at 12:57 AM ·
dragrecttransformdroprectangle
RectangleContainsScreenPoint works backwards.
My Canvas is Screen Space - Camera, Render Camera is one and only Main Camera.
I have droppable object with with that code and it works flawlessly:
public void OnDrag(PointerEventData eventData)
{
Vector3 screenPoint = Input.mousePosition;
screenPoint.z = 100.0f; //distance of the plane from the camera
transform.position = Camera.main.ScreenToWorldPoint(screenPoint);
}
public void OnEndDrag(PointerEventData eventData)
{
transform.localPosition = Vector3.zero;
}
I also have a drop zone with:
public void OnDrop(PointerEventData eventData)
{
RectTransform invPanel = transform as RectTransform;
GameObject droppedObject = eventData.pointerDrag;
if (RectTransformUtility.RectangleContainsScreenPoint(invPanel, Input.mousePosition))
{
Debug.Log("Stuff Happens");
}
else
{
Debug.Log("Nothing happens");
}
And well, it works. But it works backwards. When i drop an object on dropzone - "Nothing happens". When i drop it somewhere else, "Stuff happens". Whats up with that? Thanks :)
Comment
Your answer
Follow this Question
Related Questions
drag and merge object 0 Answers
2D Drag and Drop, but not when slot is already full 0 Answers
Drag and drop to a specific panel 0 Answers
Disabling a drag and drop script 0 Answers
Drag and Drop get the slots occupied 0 Answers