Hello! I’m working on an inventory script and having a bit of trouble with the IPointerClickHandler and the IDragHandler. Currently, my code executes everything in OnDrag() and OnEndDrag() properly, but when i let go of an item, it also registers a normal LMB click. How to prevent this?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class ItemClickHandler : MonoBehaviour, IDragHandler, IEndDragHandler, IPointerClickHandler
{
public Transform itemMenu;
public Transform inventory;
public Transform slot;
//Store currently dragged item
public void OnDrag(PointerEventData dragData)
{
transform.position = Input.mousePosition;
transform.SetParent(inventory);
transform.SetAsLastSibling();
}
public void OnEndDrag(PointerEventData endDragData)
{
transform.SetParent(slot);
transform.SetAsLastSibling();
transform.localPosition = Vector3.zero;
//assign currently dragged item to the inventory slot array it was dropped on and put old otem in the old slot
}
public void OnPointerClick(PointerEventData eventData)
{
if (eventData.button == PointerEventData.InputButton.Left)
{
Debug.Log("Using item in " + name);
//USE ITEM
}
else if (eventData.button == PointerEventData.InputButton.Middle)
{
//if item associated with inventory slot isStackable, split stack.
//change split size with mouse wheel
}
else if (eventData.button == PointerEventData.InputButton.Right)
{
Debug.Log("Opening item menu for " + name);
//OPEN ITEM MENU
}
}
}