- Home /
Move a UI element with respect to canvas scaler
I have some UI elements I'd like to move, and the canvas has a Canvas Scaler set to Scale With Screen Size with a reference resolution of 1080x1920 (it's a mobile game).
So, for an iPhone 7 Plus, canvas.rect's size is 1080x1920, for an iPhone 5S it's 1080x1917. If, for example, I'd like to move something off to the right of the screen, I'd do something like
obj.position = new Vector2(canvas.rect.width * 1.5f, obj.position.y);
But this doesn't work, because .position
expects a position in Screen pixels ( Screen.width * 1.5f
in this example).
How can I set the position of a UI element within the scaled coordinates rather than screen pixels?
Your answer
Follow this Question
Related Questions
Transform to RectTransform Conversion 1 Answer
Converting to "Rect Transform" permanently deleted part of my project 0 Answers
Different Normal vs Debug Mode values in Inspector. RectTransform bug may be? 0 Answers
GetLocalCorners not working correctly 1 Answer
Moving RectTransform over another RectTransform under GridLayout 0 Answers