To get the exact click position of the mouse on the screen, do not write randomly, what conversion coordinate system, what Ray Ray detection is a cloud.
1, the conversion coordinate system is only relative, and can not accurately achieve the current mouse click on the screen position;
2,ray detection, hit is the need to collide, no collision, get what?? (0,0,0).
So, take a look at the following positive solutions.
When I converted with a coordinate system, I found that there was no change in the value and there was a mess online.
Actually very simple, input.mouseposition itself is the screen coordinates (two-dimensional),
cannot be used directly because the screen datum point in the center of the screen, you need to lose one-second coordinate values, that is, minus one-second screen width, height.
Place the datum point in the lower-left corner of the screen, which is (0,0) in the lower-left corner.
At this point the screen coordinates of the m_panel correspond to the x, y values of the tranpos.
Transform (recttransform) M_panel;
float X = input.mouseposition.x-screen.width/2f;
float Y = input.mouseposition.y-screen.height/2f;
Vector2 Tranpos = new Vector2 (x, y);
M_panel.localposition = Tranpos;
Note: You need to consider the M_panel anchor point, for example: So to speak, the anchor point corresponds to the coordinate center point.
Unity Ugui gets the exact click position of the mouse on the screen