How to get the bottom left and top right corner of a button in screen coordinates if the button is on an Overlay Canvas? It should depend on screen.width and screen.height.
CodePudding user response:
You can use GetWorldCorners
, when the canvas is an overlay canvas, the world positions are equal to screen positions.
var corners = new Vector3[4];
GetComponent<RectTransform>().GetWorldCorners(corners);
// corners[0]: bottom-left
// corners[2]: top-right
If your canvas is an screen camera canvas, you need to convert them with camera's WorldToScreenPoint
method.