var rect =transform. Get Component<recttransform>();
rect. anchoredposition +=eventdata. delta;
var rect =transform. Get Component<recttransform>();
rect. anchoredposition +=eventdata. delta;
实现拖动的另一种方式:
继承IDragHandler接口,实现OnDrag方法。具体代码如下:
public class Test3 : MonoBehaviour,IDragHandler {
// Use this for initialization
void Start () {
}
public void OnDrag(PointerEventData eventData)
{
var rect = transform.GetComponent<RectTransform>();
rect.anchoredPosition += eventData.delta;
}
}
有时候Delta会很大,图片跟随不够
car rect=trnasform.getcomponent<recttransform>();
rect.anchoredposition+=eventdata.delta
eventdata.delta可以反馈光标每移动一小格停留的坐标
这个方法有一定的误差
dragging
Ondrag + eventData.delta实现拖拽