- Home /
How does OnBeginDrag work?
I cant get OnBeginDrag to fire at all. I created a scene with nothing but a camera and a Canvas with a UI panel with the below script, and it doesn't fire when I click on it then move the mouse. public class ItemData : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler { public void OnBeginDrag(PointerEventData eventData) %|-1233518199_1|% Debug.Log("Beggining Drag"); %|1112063221_3|% }
I have no idea how this interface is supposed to work, the tutorial videos I have seen just add the interfaces to a script in the UI element and it just magically works. Does the panel need to pickup raycasts? What am I doing wrong?
Answer by Fire_Cube · Jul 06, 2016 at 08:40 AM
You have to add the component canvas element to the object, and check the "stop raycast" toggle (not sure for the name but, something like that...)
That should do :)
Answer by YoungDeveloper · Jul 06, 2016 at 08:50 AM
Do you have any UI component attached which can receive raycast (toggle on)? For example, an Image or Text.
Yes, you just have to add the canvas group component on them, and after that, you can just use some message function, like On$$anonymous$$ouseClick, ect...
just check on the UI tutorial section. Another point, you can just use button, it's as easy ;)
Your answer
![](https://koobas.hobune.stream/wayback/20220612084126im_/https://answers.unity.com/themes/thub/images/avi.jpg)