如果按鈕位于覆寫畫布上,如何在螢屏坐標中獲取按鈕的左下角和右上角?它應該取決于 screen.width 和 screen.height。
uj5u.com熱心網友回復:
您可以使用GetWorldCorners, 當畫布是覆寫畫布時,世界位置等于螢屏位置。
var corners = new Vector3[4];
GetComponent<RectTransform>().GetWorldCorners(corners);
// corners[0]: bottom-left
// corners[2]: top-right
如果您的畫布是螢屏相機畫布,則需要使用相機的WorldToScreenPoint方法對其進行轉換。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/485834.html
下一篇:Assets\Scripts\PlayerMovement.cs(18,9):錯誤CS0029:無法將型別“void”隱式轉換為“System.Action...”
