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