So was trying some unity code with mouse input exported as a windows exe with “resizable window” ticked and there is a bug with the coordinates returned after resizing the window (upwards?) sometimes - when you click in the window beyond where the previously-sized window was the coordinates get ‘cropped’ to the old smaller size.
(i.e. Mouse Coordinates sometimes wrongly reported after window re-sized!)
Any known issue here?
It is not easy to replicate consistently but is a pain when it occurs as mouse clicks throughout certain areas of the window start returning the same x or y coordinate cropped to a min value - Windows 7, latest Unity 4.6.1
I wrote this code that really fixes this bug. Of course you should temporarily use it until Unity3d-team fix the bug.
When resolution is changed this code calls function SetResolution(). It makes update internal parameter like screen size for Input.mousePosition. Afther that it works perfectly.
You should create an object of ScreenGuard and call Update() every frame (or you can convert this class to Monobehaviour).
using UnityEngine;
/// <summary>
/// Should use temporarily until Unity3d-team fix the bug
/// http://issuetracker.unity3d.com/issues/input-when-resizing-window-input-dot-mouseposition-will-be-clamped-by-the-original-window-size
/// </summary>
class ScreenGuard
{
private int prevWidth;
private int prevHeight;
private bool isInited = false;
private void Init()
{
prevWidth = Screen.width;
prevHeight = Screen.height;
isInited = true;
}
private void SetResolution()
{
prevWidth = Screen.width;
prevHeight = Screen.height;
Screen.SetResolution(Screen.width, Screen.height, Screen.fullScreen);
}
public void Update()
{
if (!isInited)
{
Init();
}
if ((Screen.width != prevWidth) || (Screen.height != prevHeight))
{
SetResolution();
}
}
}