RectTransformUtility.ScreenPointToWorldPointInRectangle使用說明


首先,看Unity Scripting API上的介紹:

public static bool ScreenPointToWorldPointInRectangle(RectTransform rect, Vector2 screenPoint, Camera cam, out Vector3 worldPoint);
描述:
將屏幕空間上的點轉換為位於給定RectTransform平面上的世界空間中的位置。cam參數應該是與屏幕點相關的相機。對於Canvas設置為“Screen Space - Overlay mode”模式的情況,cam參數應該為null。

 

示例:Vector2 position;

           RectTransformUtility.ScreenPointToWorldPointInRectangle(GameObject.Find("Canvas").transform as RectTransform,Input.GetmousePosition,null,out positoin) // 將當前所在像素坐標的鼠標位置轉換為Canvas物體所在平面上的世界空間中的位置,將位置信息返回給position


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM