i want to drag object from point p1 to point p2.
But when dragging an object, the object must follow the direction line and restrict the drag outside of direction line.
You can get x position of mouse and calculate y. In this particular case it would be y = 3x - 10.
And may be you will need to cut positions outside the segment.
bool followingModeOn = false;
void OnMouseDown()
{
followingModeOn = true;
}
void OnMouseUp()
{
followingModeOn = false;
}
void Update()
{
if(followingModeOn)
{
float x = Camera.main.ScreenToWorldPoint(Input.mousePosition).x
transform.position = new Vector2(x, 3 * x - 10)
}
}