- Home /
BoxCollider2D only registers clicks in top right quarter of its region
I have a BoxCollider2D on an object that spans the whole screen. The object "dims the lights" while I display other information, and I want to make it so that when the user clicks on this object, the notification and this object is set inactive.
The problem is that when the offset is (0,0) and the size matches my screen, only the top right quadrant of the collider registers clicks. To get the whole object to register clicks, I have to add an offset of -(width of rect transform / 2) and -(height of rect transform / 2). This causes the mouse events to be received as expected, but the outline of the collider in the editor doesn't reflect it, as shown below:
My mouse event:
private void OnMouseDown()
{
optionsPane.SetActive(false);
}
BoxCollider2D options:
Am I doing something wrong? Why are the collision boundaries not matching where the clicks are registered? I am on Unity 2018.3.0f2
I tried looking at this again today by using Raycast2D and that also had the same problems. So I switched from a collider to an UI Button and everything works as expected now.
I've spent a few hours searching for anyone who has had this issue, and I'm starting to think this might be a problem with my install somehow. If I run into issues with BoxCollider2D again, I may reinstall and post an update here. But for now, I'm going to work around it with UI Elements.