Camera.screentoworldpoint
Vector3 Screentoworldpoint (Vector3 position);
Converts screen coordinates to world coordinates.
How to convert? Given a so-called screen coordinate (x, y, z), how do you convert it to world coordinates?
First, we need to understand how the camera renders the object:
The camera's rendering range for the game world is a flat-truncated body, and the rendering boundary is a rectangle that intercepts the flat-truncated body with a plane parallel to near Clippingplane or far clippingplane, and can obtain countless parallel rectangular faces, the screen rectangle we see. The farther away from the camera, the larger the rectangle, the closer the camera is to the smaller the rectangle. So, objects of the same size, as they get farther away from the camera, tend to look smaller and smaller relative to the corresponding screen rectangles.
On the screen, the position of a pixel relative to the screen rectangle can correspond to the position of a point in the game world relative to a section, and the key is the section on which the point is located, that is, how far this section is from the camera!
In Screentoworldpoint this method, the parameter is a three-dimensional coordinate, in fact, the screen coordinates can only be two-dimensional coordinates. The z-coordinate in the parameter is used to indicate the distance from the camera to the above plane.
In other words, given a coordinate (x, y, z),
First, we intercept a plane p that is perpendicular to the z axis of the camera, and the distance is Z, so that regardless of how X, y changes, the returned points are only on this plane;
Then, X, y represents pixel coordinates and, depending on the location of the (x, y) relative to the screen, gets the position of the point in the game world in relation to the section P, and we also convert the screen coordinates to world coordinates.
The statement in the official website document:
Camera.screentoworldpoint
Vector3 Screentoworldpoint (Vector3 position);
Description
Transforms position from the screen space to the world space.
Screenspace is defined in pixels. The bottom-left of the screen is (0,0); The Right-top is (pixelwidth,pixelheight). The z position is on world units from the camera.
transferred from: http://blog.csdn.net/czlilove/article/details/21173669
Coordinate system in unity--screen to world coordinates