Unity3D cannot use the mouse click control when displaying multiple screens
Posted: 25 Nov 2019, 10:02
When Unity is running on multiple screens, I can't hit the control with the mouse, so I added the following code under NoesisView.cs. Sorry, I changed the code.
Because Unity will display these screens as a whole when displaying multiple screens at the same time, your mouse coordinates are the coordinates in this large screen.
If I want to click on the control, I will do the following operation
If the runtime changes the value of Camera's targetDisplay, the offset becomes the wrong value.
Because Unity will display these screens as a whole when displaying multiple screens at the same time, your mouse coordinates are the coordinates in this large screen.
Code: Select all
private float offset;
void Start()
{
offset = MultiScreenPosition();
}
public float MultiScreenPosition()
{
float offset = 0.0f;
#if !UNITY_EDITOR
int targetDisplay = _myCamera.targetDisplay;
for (int i = 0; i < targetDisplay; i++)
{
Display display = Display.displays[i];
if (display != null)
{
offset += display.renderingWidth;
}
}
#endif
return offset;
}
Code: Select all
_mousePos = UnityEngine.Input.mousePosition;
_mousePos.x -= offset;
UnityEngine.Vector2 mouse = ProjectPointer(_mousePos.x, _mousePos.y);