IDragHandler not called

Hi guys,

I wanted to try out Unity Event System, so I did the following:

  • Added EventSystem in scene by click GameObject > UI > Event System
  • Added a Physics Raycaster onto the Main Camera by clicking Component > Event > Physics Raycaster
  • Added the following script onto the Main Camera:
using UnityEngine;
using System.Collections;
using UnityEngine.Events;
using UnityEngine.EventSystems;

public class MovementController : MonoBehaviour, IDragHandler {

    #region IDragHandler implementation
    void IDragHandler.OnDrag (PointerEventData eventData)
    {
        Debug.Log ("Drag Detected!");
        throw new System.NotImplementedException ();
    }
    #endregion

    // Use this for initialization
    void Start () {
   
    }
   
    // Update is called once per frame
    void Update () {
   
    }
}

But it doesn’t seem to detect any of my drag when I play. I’m not sure what I missed.

Looking forward to your help!

What you are trying to achieve?Drag on a ui element?
If so ,then you have to create a ui → button, image etc and then add your script to that.

you could call only

void OnDrag (PointerEventData eventData)
    {
        Debug.Log ("Drag Detected!");
        throw new System.NotImplementedException ();
    }

The problem is that you are putting this onto Main Camera, this script needs to be on an object with a collider on it.