- Home /
How to set RectTransform position relative to another RectTransform
I have a map as a UI.Image, I what to place another UI.Image representing a treasure chest on top of the map (in a script obviously).
I added an "Aspect Ration Fitter" to my treasure image in "Fit In Parent" aspect mode and made my map image the parent, this way I can make sure the treasure image size is always correct when the Map size changes by different screen resolutions.
My problem is with setting the treasure image position, if I set the Pivot or PosX, PosY this is always related to the entire canvas and does not remain in the right place when the map resizes ..
Can anyone suggest a way to do it ?
Answer by allenallenallen · Aug 12, 2015 at 10:16 AM
Say you want it to be Top Left corner. Set the image to Top Left along with the anchors and all.
Then you can determine the X and Y offset based on another transform.