Unity UI create and drag with one click
Hey all,
I have code that will create a new Unity UI panel at my mouse position when I left click my mouse. I want to then be able to drag that new UI panel in the same left click event. I can't figure out how to enable the drag within the same left click event.
I can successfully drag the new UI panel if un-click and re-click the panel, using OnDrag(PointerEventData data). But I want to be able to click and drag in the same left click event.
After creating the UI panel, I tried creating my own PointerEvent but the event is still not forcing the new UI panel to be selected.
EventSystem.current.SetSelectedGameObject(puzzleDragPanel);
var pointer = new PointerEventData(EventSystem.current);
ExecuteEvents.Execute(puzzleDragPanel.gameObject, pointer, ExecuteEvents.pointerEnterHandler);
ExecuteEvents.Execute(puzzleDragPanel.gameObject, pointer, ExecuteEvents.pointerDownHandler);
ExecuteEvents.Execute(puzzleDragPanel.gameObject, pointer, ExecuteEvents.pointerClickHandler);
ExecuteEvents.Execute(puzzleDragPanel.gameObject, pointer, ExecuteEvents.dragHandler);
ExecuteEvents.Execute(puzzleDragPanel.gameObject, pointer, ExecuteEvents.initializePotentialDrag);
Any ideas?
Thanks
Comment