- Home /
OnPointerEnter not triggering while dragging UI elements
So I'm trying to make a draggable inventory system using EventSystem. I can drag items only to slots that are lower in hierarchy than a slot from where I'm dragging an item. I tried debugging and it seems that OnPointerEnter is not triggering for slots that are higher is hierarchy. I have no idea why is that happening or how to fix it.
I have this script attached to slot prefabs.
public class SlotController : MonoBehaviour,IPointerEnterHandler {
public void OnPointerEnter(PointerEventData data) {
BasicUI.selectedSlot = this.transform;
}
}
and this script attached to item prefab.
using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class ItemController : MonoBehaviour,IBeginDragHandler,IDragHandler,IEndDragHandler {
public void OnBeginDrag(PointerEventData data) {
BasicUI.selectedItem = this.transform;
}
public void OnDrag(PointerEventData data) {
this.transform.position = Input.mousePosition;
}
public void OnEndDrag(PointerEventData data) {
if (BasicUI.selectedSlot.childCount == 0) {
this.transform.SetParent (BasicUI.selectedSlot);
}
this.transform.localPosition = Vector3.zero;
BasicUI.selectedItem = null;
}
}
To illustrate this
Your answer
Follow this Question
Related Questions
Create UI Mask from Childrens images 2 Answers
How to render ParticleSystem between two Image in uGUI ? (i mean UI which appeared in Unity 4.6) 0 Answers
touched ui element name C# 1 Answer
Detect 2d items only on areas where the sprite covers, and not the whole box! 0 Answers
UI Material Property Block 1 Answer