3 回答
TA贡献1777条经验 获得超10个赞
您可能未Camera.ScreenToWorldPoint正确调用该方法。特别是,应将传递给此方法的屏幕位置参数的z位置定义为相机的世界单位。请参阅Camera.ScreenToWorldPoint上的Unity文档。
相反Camera.main.ScreenToWorldPoint(Input.mousePosition),我认为这是正确的调用方式Camera.ScreenToWorldPoint:
var cameraPosition = Camera.main.transform.position;
// assuming `transform` is the transform "Virtual Screen Quad"...
float zWorldDistanceFromCamera = transform.position.z - cameraPosition.z;
var screenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, zWorldDistanceFromCamera);
var worldPoint = Camera.main.ScreenToWorldPoint(screenPoint);
Debug.LogFormat("mousePosition: {0} | zWorldDistanceFromCamera: {1} | worldPoint: {2}",
Input.mousePosition,
zWorldDistanceFromCamera,
worldPoint.ToString("F3"));
(如果这行不通,您是否可以更新您的问题?)
- 3 回答
- 0 关注
- 400 浏览
添加回答
举报