The Parent object is a moving rectangle and inside the rectangle there is another rectangle.
the parent moving to right continuously and the child rectangle moving up and down.
Uhm, just use child.localPosition and use a local position inside the parent space as target point. If you want to prevent the object from leaving or intersecting the border of the parent you just have to choose target points which are inside the parent. You presented this problem in a very generic / abstract way.
Lets assume the pivot of the parent is the center of the parent and the pivot of the child is the center of the child. We also assume that the parent and child objects have a scale of (1,1,1). We further assume that the parent rect has a side length of xS and yS and the child object has a size of xSc and ySc.
That means the local y coordinate inside the parent goes from border to border:+yS/2 to -yS/2. However since the child has a height of “ySc” we have to subtract half that from the possible target range. So the valid range for the child goes from (yS - ySc)/2 to -(yS - ySc)/2 on the y axis.