I am trying to make a draging effect. I have a project where u are supposed to pull a bone out of meat. The draging is working, but when i grab the bone i can move it in all directions. What i would like to achieve is that i can only drag it in one direction. On the images below i mean the red line. I tried many things but nothing worked so far. Any help is appreciated.
I used these functions for the draging
void OnMouseDown()
{
offset = this.transform.position - Camera.main.ScreenToWorldPoint(new Vector2(transform.position.x, Input.mousePosition.y));
}
void OnMouseDrag()
{
Vector3 curScreenPoint = new Vector2(transform.position.x, Input.mousePosition.y);
Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset;
transform.position = curPosition;
}