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));
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.
本文详细解释了Unity中ScreenToWorldPoint方法的正确使用方式,并指出了常见错误及其修正方法。文章强调了在不同摄像机模式下,如透视模式和正交模式,该方法的参数设置差异。
3884







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