Unity coordinate screen vs world vs GUI
Screenspace is defined in pixels. The bottom-left of the screen is (0,0); the right-top is (pixelWidth,pixelHeight). The z position is in world units from the camera.
GUI if top_left 0,0 like winform or wpf .
Viewport space is normalized and relative to the camera. The bottom-left of the camera is (0,0); the top-right is (1,1). The z position is in world units from the camera.
// detect the left mouse button down
if (Input.GetMouseButton(0))
{
Vector3 position = Input.mousePosition;
//mouse position is screen space
Debug.Log(string.Format("position is x :{0}, y :{1}", position.x, position.y));
var wtoscreen = camera.WorldToScreenPoint(position);
// Debug.Log("wtoscreen postion is x :{0}, y: {1}; and mouse position is x :{2}, y:{3}",wtoscreen.x,wtoscreen.y,position.x,position.y);
//wtoscreen postion is x :6465.1, y: 24189.3; and mouse position is x :118, y:454
//this is wrong solution, so i think the worldtoscreenpoint function should was used by gameobject in the world not mouse position
Debug.Log(string.Format("wtoscreen postion is x :{0}, y: {1}; and mouse position is x :{2}, y:{3}", wtoscreen.x, wtoscreen.y, position.x, position.y));
}

浙公网安备 33010602011771号