Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

IDragHandler not called

Discussion in 'Scripting' started by _Shade, May 16, 2015.

  1. _Shade

    _Shade

    Joined:
    Dec 9, 2014
    Posts:
    5
    Hi guys,

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

    1. Added EventSystem in scene by click GameObject > UI > Event System
    2. Added a Physics Raycaster onto the Main Camera by clicking Component > Event > Physics Raycaster
    3. Added the following script onto the Main Camera:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.Events;
    4. using UnityEngine.EventSystems;
    5.  
    6. public class MovementController : MonoBehaviour, IDragHandler {
    7.  
    8.     #region IDragHandler implementation
    9.     void IDragHandler.OnDrag (PointerEventData eventData)
    10.     {
    11.         Debug.Log ("Drag Detected!");
    12.         throw new System.NotImplementedException ();
    13.     }
    14.     #endregion
    15.  
    16.     // Use this for initialization
    17.     void Start () {
    18.    
    19.     }
    20.    
    21.     // Update is called once per frame
    22.     void Update () {
    23.    
    24.     }
    25. }
    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!
     
  2. tranos

    tranos

    Joined:
    Feb 19, 2014
    Posts:
    180
    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
    Code (CSharp):
    1. void OnDrag (PointerEventData eventData)
    2.     {
    3.         Debug.Log ("Drag Detected!");
    4.         throw new System.NotImplementedException ();
    5.     }
     
    Last edited: May 17, 2015
  3. bigbadtrumpet125

    bigbadtrumpet125

    Joined:
    Apr 1, 2013
    Posts:
    18
    The problem is that you are putting this onto Main Camera, this script needs to be on an object with a collider on it.