Unity 上下拖动图片
using UnityEngine; using UnityEngine.EventSystems; using DG.Tweening; public class MoveObj : MonoBehaviour, IDragHandler, IPointerDownHandler { //private Vector2 offsetPos; //临时记录点击点与UI的相对位置 //public void OnPointerDown(PointerEventData eventData) //{ // offsetPos = eventData.position - (Vector2)transform.position; //} //public void OnDrag(PointerEventData eventData) { // transform.position = eventData.position - offsetPos; //} private Vector2 offsetPos; //临时记录点击点与UI的相对位置 private float posX; private float posY; public void OnPointerDown(PointerEventData eventData) { offsetPos = eventData.position - (Vector2)transform.position; posX = transform.position.x; } public void OnDrag(PointerEventData eventData) { posY = eventData.position.y - offsetPos.y; Vector2 pos = transform.position; pos.y = posY; // transform.position = pos; transform.DOMoveY(posY, 0.2f); } }
posted on 2020-09-07 09:25 zqiang0803 阅读(318) 评论(0) 编辑 收藏 举报