Using Unity 2018.3.11f1, I am building an application that spans across two separate screens. How can I determine which screen a touch (or mouse click) occurred on?
Below please see my attempt. The problem is that for this to work, I need a way to determine which camera/display to use for my raycast hit test. How do I do that?
// if the left/primary mouse button has been pressed
if( Input.GetMouseButton(0) || Input.GetMouseButtonDown(0) || Input.GetMouseButtonUp(0) ) {
// get both cameras
Camera display1Camera = GameObject.Find( "Display1Camera" ).GetComponent<Camera>();
Camera display2Camera = GameObject.Find( "Display2Camera" ).GetComponent<Camera>();
Camera displayActiveCamera = MagicFunctionThatDeterminesWhetherClickWasOnScreen1OrScreen2( Input, display1Camera, display2Camera ); // This is what I am missing
// create a ray from the active camera to the click position
Ray ray = displayActiveCamera.ScreenPointToRay( Input.mousePosition );
// check if the ray hit anything
if( Physics.Raycast( ray, out hit, touchInputMask) ) {
// get the game object that was hit
GameObject recipient = hit.transform.gameObject;
// interact with it
if( Input.GetMouseButtonDown(0) ) {
recipient.SendMessage( "OnTouchDown", hit.point, SendMessageOptions.DontRequireReceiver );
}
}
}