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?
@Suguma 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.MouseDown, MouseUp, 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!
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
3 People are following this question.
Hide/show UI Button and trigger the OnPointerDown event ?!
Unity 4.6: Drag and drop
How to drag gameobjects (other than ui elements) using the event trigger?
Can't fire a Custom Event on UI Button Touch OnClick
Correct way to send an event to a specific enemy