Author Topic: Hard Limit UIDragObject  (Read 1581 times)

justinISO

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 52
    • View Profile
Hard Limit UIDragObject
« on: October 25, 2016, 11:22:47 AM »
Hello,

I have a UIDragObject that I want to limit the vertical dragging (on the y-axis) so the user cannot drag it further than my limits.

I have a check in OnDrag that looks like this:

  1. void OnDrag(Vector2 delta)
  2. {
  3.     if(transform.localPosition.y > maxY){
  4.         //Limit the drag motion here
  5.     }
  6. }

But I am not really sure how to limit the dragging. If I set the position of the object to the limit, the dragging doesn't stop and when I let go to center it again, it was offset by how much I continued to drag.

Thanks!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Hard Limit UIDragObject
« Reply #1 on: October 30, 2016, 11:55:00 AM »
UIDragObject has a flag for that -- restrict within panel. If you set it along with the panel region, it won't be possible to exceed the chosen panel's bounds. The math is all there as well, I just call panel.ConstrainTargetToBounds on line 183 of UIDragObject.cs