What do I have:
Camera2Dthat looks down on the Plane, horizontally in a global system- The Image from Camera2D is saved to the Texture2D
MainCamerawhich displays Canvas from the UI- There is a
RawImagein Canvas to which Texture2D is assigned
In short, in Main UI I have a screen in which I display the content of another camera.
My problem:
- I'd like to draw something on
Plane. - To do this I need to find a mapping of the Mouse Position in the global coordinate system
I try to do it in different ways, e.g.
var mp = Input.mousePosition;
var vec = mainCamera.ScreenToWorldPoint(mp);
//var vec = image2DCamera.ScreenToWorldPoint(mp);
This solution works when there is only one camera, but in this case it does not fulfill its purpose.
How to do it correctly in such a situation?
EDIT:
Plane plane = new Plane(new Vector3(0, 0, 0), new Vector3(1, 0, 0), new Vector3(0, 0, 1));
float distance;
var mp = Input.mousePosition;
var mp2 = new Vector3(mp.x, mp.y, 100);
Ray ray = image2DCamera.ScreenPointToRay(mp2);
if (plane.Raycast(ray, out distance))
{
worldPosition = ray.GetPoint(distance);
}
Debug.Log("mp : " + mp2);
Debug.Log("worldPosition : " + worldPosition);

