I don’t understand why I can’t get the onDrop event to trigger. I am using a tutorial to create an inventory. His works in his video, but in my code, the OnDrop simply does not ever get called. It’s driving me nuts and I can’t find any other support for this issue.
using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
public class Slot : MonoBehaviour, IDropHandler, IDragHandler, IBeginDragHandler, IEndDragHandler
{
#region IEndDragHandler implementation
public void OnEndDrag(PointerEventData eventData)
{
}
#endregion
#region IBeginDragHandler implementation
public void OnBeginDrag(PointerEventData eventData)
{
}
#endregion
#region IDragHandler implementation
public void OnDrag(PointerEventData eventData)
{
}
#endregion
public GameObject item
{
get
{
if(transform.childCount>0)
{
Debug.Log("1");
return transform.GetChild (0).gameObject;
}
return null;
}
}
#region IDropHandler implementation
public void OnDrop (PointerEventData eventData)
{
Debug.Log("3");
if(!item)
{
Debug.Log("2");
DragHandler.itemBeingDragged.transform.SetParent (transform);
}
}
#endregion
}
using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
public class DragHandler : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler, IDropHandler
{
public static GameObject itemBeingDragged;
Vector3 startPosition;
Transform startParent;
#region IDropHandler implementation
public void OnDrop(PointerEventData eventData)
{
Debug.Log("why");
}
#endregion
#region IBeginDragHandler implementation
public void OnBeginDrag(PointerEventData eventData)
{
Debug.Log("4");
itemBeingDragged = gameObject;
startPosition = transform.position;
startParent = transform.parent;
GetComponent<CanvasGroup>().blocksRaycasts = false;
}
#endregion
#region IDragHandler implementation
public void OnDrag(PointerEventData eventData)
{
Debug.Log("5z");
transform.position = Input.mousePosition;
}
#endregion
#region IEndDragHandler implementation
public void OnEndDrag(PointerEventData eventData)
{
Debug.Log("6");
itemBeingDragged = null;
GetComponent<CanvasGroup>().blocksRaycasts = true;
if (transform.parent == startParent)
{
Debug.Log("7");
transform.position = startPosition;
}
}
#endregion
}