Drag a object along curves

I want to drag an 2d object along a curvy 2dpath
if the player drag in right path the object gets drag or else not , check the file attached

what I tried is on mouse drag I raycast through the object and checked if it hit the path then move else not but its not working smoothly
and the object freezes

RaycastHit2D hits;![42981-pathline.png|1160x1880](upload://yNjwMezeI9oFibUu7zYcL2Tei8p.png)
	hits = Physics2D.Raycast(transform.position, -Vector3.back, 10000f,7) ;
	if(hits.collider != null && hits.collider.tag== "path" )
		Lastpos = hits.point;
		print (hits.collider);
		Vector3 pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
		transform.position= new Vector3(pos.x,pos.y,-0.1419618f);



Try to set a path as array of Vector3s, and every time mouse changes position, find closest point from array to your mouse’s position. If its smaller then some constant allowable value - move your object, otherwise don’t do anything.