I looked at the demo Drag and Drop example and it’s actually something very close to what I was implementing in my project, but I’m running into a problem: OnBeginDrag seems to completely trump OnPointerClick.
Basically, I like the drag-and-drop functionality, but if a player just clicks the image then something else happens and I can’t figure out how to do this.
Hi
Just add IPointerClickHandler interface to demo DragMe script
and move icon creation from OnBeginDrag to OnDrag event like so:
public void OnDrag(PointerEventData data)
{
if (m_DraggingIcon == null)
{
var canvas = FindInParents<Canvas>(gameObject);
if (canvas == null)
return;
// We have clicked something that can be dragged.
// What we want to do is create an icon for this.
m_DraggingIcon = new GameObject("icon");
m_DraggingIcon.transform.SetParent(canvas.transform, false);
m_DraggingIcon.transform.SetAsLastSibling();
var image = m_DraggingIcon.AddComponent<Image>();
// The icon will be under the cursor.
// We want it to be ignored by the event system.
m_DraggingIcon.AddComponent<IgnoreRaycast>();
image.sprite = GetComponent<Image>().sprite;
image.SetNativeSize();
if (dragOnSurfaces)
m_DraggingPlane = transform as RectTransform;
else
m_DraggingPlane = canvas.transform as RectTransform;
}
SetDraggedPosition(data);
}
oh, and you can remove IBeginDragHandler because it’s not suppose to do anything now