I am trying to build a menu with a cursor. I created the menu and that in the unity UICamera on the canvas. It looks great. I want the cursor to move so what I did was move the cursor by hand and record the values at each location I want the cursor to possibly be (see attached). The problem is later when I try to set the value to these via this:
It fails and looking in the inspector again the x,y values are like 300, 800 or something. I am guessing I need a conversion I just am not sure where or how. Do I get the Ui camera reference and use the WorldToScreen?
Quick answer:
instead of setting rectTransform.position, set rectTransform.localPosition
Why:
The position you see in the inspector is a localPosition, meaning it’s a position relative to it’s parent. So position (0, 0, 0) would be at the same exact position as the parent. The local position is also scaled by the parents scale, so position (1, 1, 1) will look like (2, 2, 4) if your parent has a scale of (0.5, 0.5, 0.25). I’m almost 100% sure your canvas has a scale that’s not (1, 1, 1).