首页 > 学院 > 开发设计 > 正文

Unity Ugui射线坐标转换总结

2019-11-11 04:19:18
字体:
来源:转载
供稿:网友

http://www.bubuko.com/infodetail-1292358.html

世界空间中的点坐标转换到屏幕坐标:

screenPos = RectTransformUtility.WorldToScreenPoint(cam, worldPos.transform.position);

UGUI物体的坐标转换到屏幕坐标:

screenPos = RectTransformUtility.WorldToScreenPoint(canvas.worldCamera, uguiObj.transform.position);

屏幕坐标转换到UGUI坐标:

Vector3 worldPoint;if (RectTransformUtility.ScreenPointToWorldPointInRectangle(rectTrans, camPos, canvas.worldCamera,out worldPoint)){  transform.position = worldPoint;}

屏幕坐标转换到世界空间坐标(射线碰撞位置):

var ray = RectTransformUtility.ScreenPointToRay(worldCamera, screenPos);RaycastHit hitInfo;if (Physics.Raycast(ray, out hitInfo)){  pos.transform.position = hitInfo.point;}


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表