Attach it to GameObject.
Assign the two RectTransforms that you want to link to the rectTransform1 and rectTransform2 variables in the inspector.
The Update method of the script will be called every frame, and it will update the position of rectTransform2 based on the current position of the right edge of rectTransform1.