I have a script running every frame that keeps the window’s aspect ratio at 16:9 whenever the screen size changes. I’ve noticed though that the SetResolution function call specifically results in strange behavior with ui buttons. After this is run just once, buttons no longer activate on a mouse click. When I click on a button, its sprite darkens indicating it was pressed, but it doesn’t activate its function until I press the spacebar.
Removing the SetResolution call completely fixes this, but I need this function in my game. What’s going on and how can I keep this function while preserving the functionality of my buttons?
The is the exact code btw:
if (triggerCondition)
{
if (Math.Abs(currentWidth - lastSetWidth) >= Math.Abs(currentHeight - lastSetHeight))
Screen.SetResolution((int)currentWidth, (int)(currentWidth * 9 / 16), false);
else
Screen.SetResolution((int)(currentHeight * 16 / 9), (int)currentHeight, false);
}