Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Drag And Drop

Discussion in 'Scripting' started by xaviergamerpro9, Jul 30, 2020.

  1. xaviergamerpro9

    xaviergamerpro9

    Joined:
    Jul 10, 2020
    Posts:
    12
    Hey, I have an issue with my drag and drop system code please look over it and reply with any way to fix it

    My Code:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.EventSystems;
    5.  
    6. public class DragAndDrop : MonoBehaviour, IPointerDownHandler, IBeginDragHandler, IEndDragHandler, IDragHandler
    7. {
    8.    
    9.     public RectTransform rect;
    10.    
    11.     private void OnDrag(){
    12.         rect.anchoredPosition += eventData.delta;
    13.     }
    14.  
    15.     private void OnBeginDrag(){
    16.         Debug.Log("Drag Started");
    17.     }
    18.  
    19.     private void OnEndDrag(){
    20.         Debug.Log("Drag Finished");
    21.     }
    22.  
    23.     private void OnPointerDown(){
    24.         Debug.Log("Object Clicked");
    25.     }
    26.  
    27. }
    Errors:

    Assets\Assets\Scripts\DragAndDrop.cs(6,100): error CS0535: 'DragAndDrop' does not implement interface member 'IDragHandler.OnDrag(PointerEventData)'

    Assets\Assets\Scripts\DragAndDrop.cs(6,83): error CS0535: 'DragAndDrop' does not implement interface member 'IEndDragHandler.OnEndDrag(PointerEventData)'

    Assets\Assets\Scripts\DragAndDrop.cs(6,64): error CS0535: 'DragAndDrop' does not implement interface member 'IBeginDragHandler.OnBeginDrag(PointerEventData)'

    Assets\Assets\Scripts\DragAndDrop.cs(6,43): error CS0535: 'DragAndDrop' does not implement interface member 'IPointerDownHandler.OnPointerDown(PointerEventData)'
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    8,455
    These errors are super clear... you have an OnDrag() but not the signature it's looking for, one that accepts a PointerEventData. That means ... wait for it ... you're not implementing the interface!

    Just use right-click implement interface.
     
    Yanne065 likes this.
unityunity