- Home /
Dragging an UI object but keep it going after letting go?
Hi,
I am using the following script to drag an UI element and limit its movement to certain max and min values in x and y.
public float minY = -3095.0f, maxY = 3095.0f;
public float minX = -3095.0f, maxX = 3095.0f;
public void OnDrag(PointerEventData eventData)
{
this.transform.localPosition += (Vector3)eventData.delta;
}
void Update()
{
Vector3 currentPosition = transform.localPosition;
currentPosition.y = Mathf.Clamp(currentPosition.y, minY, maxY);
currentPosition.x = Mathf.Clamp(currentPosition.x, minX, maxX);
transform.localPosition = currentPosition;
}
Right now as soon as I don't press the MouseButton the movement stops immediately. Is it possible to slowly let the movement get slower similar to how you would scroll a website on a mobile phone. So you scroll and the momentum keeps it going until it comes to a stop shortly after letting go?
Any help is much appreciated!
Comment