Author Topic: [UPDATE] UIDragObject.OnDrag question  (Read 2263 times)

Kafar

  • Newbie
  • *
  • Thank You
  • -Given: 10
  • -Receive: 0
  • Posts: 27
    • View Profile
[UPDATE] UIDragObject.OnDrag question
« on: December 04, 2017, 06:51:04 AM »
In the OnDrag event I need to check the drag direction.
Can how check it?
I wrote this code below but when I drag the game object, it always move to the left.
Thanks

  1. void OnDrag(Vector2 delta)
  2.         {
  3.                
  4.                 if (transform.localPosition.x > 0)
  5.                         rigidBody.AddForce (Vector3.right * 20, ForceMode.Impulse);
  6.  
  7.                 if (transform.localPosition.x < 0)
  8.                         rigidBody.AddForce (Vector3.left * 20, ForceMode.Impulse);
  9.  
  10.                 if (transform.localPosition.y < 0)
  11.                         rigidBody.AddForce (Vector3.down * 20, ForceMode.Impulse);
  12.  
  13.                 if (transform.localPosition.y > 0)
  14.                         rigidBody.AddForce (Vector3.up * 20, ForceMode.Impulse);
  15.  
  16.  
  17.  
  18.         }
  19.  
  20.  
« Last Edit: December 05, 2017, 07:14:13 AM by Kafar »

cmifwdll

  • Global Moderator
  • Sr. Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 149
  • Posts: 285
  • TNet Alchemist
    • View Profile
Re: [UPDATE] UIDragObject.OnDrag question
« Reply #1 on: December 07, 2017, 03:52:09 AM »
I don't have NGUI but wouldn't you want to be checking the delta arg instead of the transform's position?