- Home /
2D Collider larger than specified
I have a bunch of UI Images that I'm using as buttons for my game and I'm using 2D raycast to determine which button is clicked on. All of them work except for this menu button. It's at the top of the screen and when I click anywhere beneath the button it registers that it's hitting the button even though it's 1000 pixels below it but it doesn't do that for any other button I have.
if (Input.GetMouseButtonDown(0))
{
RaycastHit2D hit2D = Physics2D.Raycast(Input.mousePosition, Vector2.down);
if (hit2D)
{
if (hit2D.collider.name == "menu_button")
{
Debug.Log("hitsomething");
}
}
Above is the only code I have that hits the button and it's exactly the same as every other code I have that I use for the other buttons. The link below is the inspector view of the object, the collider fits perfectly over the button in the scene view and stays that way so I'm at a loss, I don't understand why this is happening.
Thank you in advanced, I'd just like to hear someones idea on why this is happening
Your answer
Follow this Question
Related Questions
Layer Mask on raycast2d not working? 1 Answer
Raycast2D will point right, but won't point left when player turns. 1 Answer
2D Raycast effect only what it hits? 2 Answers
Raycast for a 2D objects 0 Answers