Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Kafar on December 04, 2017, 06:51:04 AM

Title: [UPDATE] UIDragObject.OnDrag question
Post by: Kafar 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.  
Title: Re: [UPDATE] UIDragObject.OnDrag question
Post by: cmifwdll 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?