Unity EventSystem中OnBeginDrag等问题:
描述:
最近做着玩想用鼠标拖拽背包物品,用上了EventSystem。出现在canvas中无法拖拽的问题using UnityEngine;
using UnityEngine.EventSystems;
public class ItemOnDrag : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
{
public void OnBeginDrag(PointerEventData eventData)
{
transform.position = eventData.position;
}
public void OnDrag(PointerEventData eventData)
{
transform.position = eventData.position;
}
public void OnEndDrag(PointerEventData eventData)
{
}
}
解决方法
勾选canvas中的 Override Sorting后设置sort order。