How to detect mouse left window?
Rect screenRect = new Rect(0, 0, Screen.width, Screen.height);
if (!screenRect.Contains(Input.mousePosition)) return;
Only works in Editor mode, mouse position become negative or greater than window size. In actual builded game in window mode mouse position stays in bounds although mouse cursor left window.
What are you trying to achieve?
Camera movement when mouse cursor is near window edge, but stop movement when mouse left window area.
Perhaps what you need is to lock cursor inside screen?
This is workaround, what I need is detect mouse cursor left window area. By the way OnMouseOver / OnMouseExit also only works detect mouse left in Editor mode.
Sounds like you might have to go with native Windows code… luckily Unity makes that pretty easy. I don’t have any recent experience with this, but it should be easy to find if you search for something like “Windows get mouse position C#” and remove Unity from your searching (i.e.-don’t limit yourself to Unity specific examples). “Back in my day” (yes, I’m old) that meant this:
…I assume they have a .NET equivalent of that, these days.