I am currently trying to make a drag and drop system where i have a dragable UI object which i can place on a other object. But i don't know how i can get the UI object below the mouse and the dragable UI object.
This is the code of my dragableObject:
using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class DragHandeler : MonoBehaviour, IBeginDragHandler, IDragHandler,
IEndDragHandler
{
public Transform parentToReturnTo = null;
public Transform placeHolderParent = null;
public void OnBeginDrag(PointerEventData eventData)
{
parentToReturnTo = transform.parent;
}
public void OnDrag(PointerEventData eventData)
{
transform.position = eventData.position;
}
public void OnEndDrag(PointerEventData eventData)
{
transform.position = parentToReturnTo.position;
}
}
and this code for my place holder:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class PlaceHolder : MonoBehaviour, IDropHandler,
IPointerEnterHandler, IPointerExitHandler
{
public void OnPointerEnter(PointerEventData eventData)
{
Transform test = eventData.pointerDrag.GetComponent<Transform>();
Debug.Log(test.name);
}
public void OnPointerExit(PointerEventData eventData)
{
}
public void OnDrop(PointerEventData eventData)
{
}
}
the problem is the OnPointerEnter Function isn't called always when it should be, it only calls it sometimes when i am over the object with my mouse. Is there maybe a other way on how i can get the current object below the dragable object?