DragHandler not registering Drag
I am trying to create a drag & drop system without using OnMouseOver, however I just can't get this to work. I have the following script attached to a Cube, which I want to be able to drag. The cube also has a collider attached. Why is it not working?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class ItemDragHandler : MonoBehaviour, IDragHandler,IEndDragHandler
{
public void OnDrag(PointerEventData eventData)
{
Debug.Log("x");
}
public void OnEndDrag(PointerEventData eventData)
{
Debug.Log("z");
}
}
$$anonymous$$ake sure that you have an Event Trigger component on your cube as well. You'll need to add a new event type of Drag and EndDrag to it; then point them to your functions. Then you also need to add a Physics Raycaster component to the camera you are using to be able to pick up those events.
The EventTrigger
component is not necessary. However, the PhysicsRaycaster
is needed for 3D objects indeed.
Your answer
Follow this Question
Related Questions
Drag the screen back and forth to left/right level (mobile) 0 Answers
Drag Finger to aim ,release to Shoot 0 Answers
[SOLVED] When touch and drag objects fast (in android), leave dragging. 1 Answer
I want to put a limit on the edges of the screen for dragable objects 1 Answer
How to end game when last item has been 'dragged and dropped'? 0 Answers