Hello,
after reading some example to move an object without centering it to mouse cursor, I still have a problem, while dragging the object becomes more and more distant to cursor.
Does anyone can help me?
this is my code:
public void OnBeginDrag(PointerEventData eventData)
{
Debug.Log("OnBeginingDrag");
distance = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y,Camera.main.WorldToScreenPoint(transform.position).z)) - transform.position;
}
public void OnDrag(PointerEventData eventData)
{
Debug.Log("OnDrag");
Vector3 distance_to_screen = Camera.main.WorldToScreenPoint(transform.position);
Vector3 pos_move = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, distance_to_screen.z ));
this.transform.position = new Vector3( pos_move.x - distance.x , pos_move.y - distance.y, transform.position.z );
}
Thank you