How to Deal with 2 Screens, 2 UIs, 2 Cameras and Five Mice

I have been working on a game for a good friend of mine and there was this thing he REALLY wanted to achieve: 2 screens with 5 mice, each screen has a different camera, each screen has its own UI.

So I was set for a challenge.

5 Mice was achieved through an asset on the asset store that allows you to read as many mouse and controller inputs as you want. So I created UI objects for each mouse, each one of them is a fake mouse cursor so Unity’s Input library becomes useless and I had to figure out how to do graphic raycasting.

Graphic raycasting in itself is NOT a problem. You can find resources for that anywhere.

The issue comes with the 2 screens, 2 UIs, 2 cameras.

I experimented with many settings, including changing the UI to Screen Space Camera, Changing priorities, etc, etc, but it always seemed like the simulated mouse clicks through Graphic Raycasting was failing.

So I switched the Graphic Raycaster to the one on the correct Canvas. This didn’t solve it either! Nothing seemed to work.

Finally, I tried with an offset. I knew the game won’t be run on external machines, only this guy’s, so I know his screen settings. One UI on the right screen, one UI on the left screen, separated by 1920 pixels.

I added a horizontal position offset of “-1920” to the simulated mouse clicks happening on the left screen UI and Voila! Then I added an actual calculation of offset and everything works well.

TL;DR: If you have multiple screen issues, try offsetting your graphic raycasts.

Leave a Reply

Your email address will not be published. Required fields are marked *