Suppose I have a UI menu for a 2D mobile game that is stretched to the whole screen. I am implementing a scroll function for all the levels in the game, so I need the left point of the screen so I can spawn the levels at the start of the screen, but I also need the right point of the screen, so I know when to stop the scrolling.
I have a GO that is parented to the left, so I already have the starting left point ( ofc, its (0, 0).)
But for the right side there is a problem. My canvas is Scale with screen size and my def res is 1920x1080. Any resolution that is bigger than it will pose a problem, so I know there is a formula.
(currentWidth / currentHeight) / (1920 / 1080) * 1920 gives you the brand new width. Am I getting it wrong?
What is a better approach at getting that point?
Screen.currentResolution.width;
should return this value but I’m not sure this is what you need.
Another way of doing it (an maybe a more useful one if your scroll doesn’t match the full screen width) might be:
RectTransform canvasRect = this.GetComponent<RectTransform>();
float realWidth = canvasRect.width * canvasRect.localScale.x;
If you don’t mind, why do you need to stop the scroll manually?