- Home /
Initiating a Drag event by code
Hi,
I have this object (a regular game object) which I'm currently able to drag around using the EventSystem. I implemented the BeginDrag, Drag and EndDrag interfaces and stuff. All working fine.
The thing is this object is instantiated when a certain button is clicked. I want the user to press the button and instantly have the object dragging with the mouse without having to click it again to trigger the drag events. I tried ExecuteEvents.Execute, but, althought it does trigger the event I tell it to, it does not trigger following events. In other words, even though I can call OnDrag or OnBeginDrag, these methods will be called once and that's it, they won't make the OnDrag event keep on happening, because the object isn't being dragged at all.
So basically I want to start dragging my game object when I click a button. Can anybody help?
@$$anonymous$$uma Were you ever able to solve this? I'm in the same situation.
Wow, it's been a long time
I don't remember exactly how I solved it, sorry, but I have two solutions I can think of:
You could try to keep your button detecting events and send them to the object you want to drag. If you don't raise your finger, the button will receive all the events event if your finger is not over it anymore.
You could create some sort of InputController that will track Input.$$anonymous$$ouseDown, $$anonymous$$ouseUp, etc, raycast for objects and everything. The UI button would then instantiate the object and pass it on to the InputController, which would drag the object without using Events
Hope it helps!
Your answer
Follow this Question
Related Questions
IPointerClickHandler works until I add IPointerDownHandler 0 Answers
Issues implementing UI event triggers via script 1 Answer
On Void Called 2 Answers
Hide/show UI Button and trigger the OnPointerDown event ?! 0 Answers
How to drag gameobjects (other than ui elements) using the event trigger? 2 Answers