using UnityEngine;
using System.Collections;
public class BeiBao : UIDragDropItem
{
protected override void OnDragDropRelease(GameObject surface)
{
base.OnDragDropRelease(surface);
//获取当前物体的父对象位置
Transform myparent = this.transform.parent;
if (surface.tag == "IsKuang") //如果是框就存进去
{
//改变父对象并且本地坐标重置为零
this.transform.parent = surface.transform;
this.transform.localPosition = Vector3.zero;
}
else if(surface.tag == "IsWuTi") //如果是物体就交换位置
{
//声明一个变量,把B的父级存起来
Transform parent = surface.transform.parent;
//B的父级换成了A的父级 并且相对位置重置为零
surface.transform.parent = myparent;
surface.transform.localPosition = Vector3.zero;
//与上同理 A - B
this.transform.parent = parent;
this.transform.localPosition = Vector3.zero;
}
else
{
//其他情况 就返回原来的地方
this.transform.parent = myparent;
this.transform.localPosition = Vector3.zero;
//Debug.Log(surface.name);
}
}
}
作者:Czhenya
链接:https://czhenya.blog.csdn.net/article/details/77775897
来源:CSDN
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。