拖动装备放到背包里
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;//导包
using UnityEngine.EventSystems;//导包
/// <summary>
/// 背包系统(一定要放在要拖动的对象的身上)
/// </summary>
public class Bag : MonoBehaviour ,IBeginDragHandler,IDragHandler,IEndDragHandler,ICanvasRaycastFilter
{
//没有穿透
bool isRayCast=true;
void Start ()
{
}
// Update is called once per frame
void Update ()
{
}
//开始拖动
public void OnBeginDrag(PointerEventData eventData)
{
//穿透
isRayCast = false;
}
//正在拖动
public void OnDrag(PointerEventData eventData)
{
//装备的位置等于鼠标的位置
this.transform.position = Input.mousePosition;
}
//结束拖动
public void OnEndDrag(PointerEventData eventData)
{
//放入
if (eventData.pointerEnter != null && eventData.pointerEnter.gameObject.tag == "grids")
{
GameObject obj = eventData.pointerEnter.gameObject;
//为装备设置父对象
this.transform.SetParent(obj.transform);
//为装备设置位置
this.transform.localPosition = Vector3.zero;
}
//取出
else
{
this.transform.SetParent(GameObject.Find("Canvas").transform);
}
//没有穿透
isRayCast = true;
}
public bool IsRaycastLocationValid(Vector2 sp, Camera eventCamera)
{
return isRayCast;
}
}