您的位置:首页 > 移动开发 > Unity3D

Unity ScreentoWorldPoint中的z坐标说明

2016-04-28 19:45 651 查看
There are two problems here. The first one is that you need a 'new' in front of your Vector3() in C#. The second is that the 'z' parameter must be the distance in front of the camera. In perspective mode at least, passing 0 will cause ScreenToWorldPoint()
to always return the position of the camera. So the call will look something like:

worldPos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x,Input.mousePosition.y, 10.0f));

[/code]
Note the measurement for the 'z' parameter is from camera plane to the playing surface plane. It is not the distance between the camera and the object. If the camera is aligned with the axes, then the distance is easy to calculate. If the camera is at an
angle (i.e. not axes aligned), then ScreenToWorldPoint() is not the way to go.

Correction/Addition: Passing '0' will work fine to find the world x,y values if the camera is Orthographic. The 'z' will be the 'z' position of the camera.

原文地址:http://answers.unity3d.com/questions/599097/need-help-understanding-screentoworldpoint.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: