- Home /
An issue related to button in world space canvas.
I have a big collider in the scene with a script attached, this script derives IPointerDownHandler, IPointerUpHandler, IPointerExitHandler, which can be clicked and reacting to the input.
Now I want to set a world space canvas, with a button in it. And when the button stay out of the collider, it works fine, but when the button stay in the collider, the input actions like mouse or touch screen are only responsed by the collider, the button has no response to the input.
The canvas is in the UI layer and sorting layer, the collider is in anonther sorting layer below it. The z position of the canvas is above all others. I also tried canvas group to block raycasts, but it doesn't solve the issue.
How to solve this?
Answer by RafiXWPT · Aug 28, 2015 at 02:11 PM
I don't know if it will help you, but I had simillar problem before and this script helped me: You have to attach it to that object which you want to click.
void OnMouseOver()
{
if(Input.GetMouseButtonDown(1) && !EventSystem.current.IsPointerOverGameObject())
{
// Things when you hit your GUI thing
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612001752im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Button is not being clicked. 1 Answer
Can I Simulate the "Submit" Event with Gamepad Buttons? 0 Answers
Button.Select(); does not highlight? 12 Answers
Can I use EventSystem + InputModule to implement scroll via button? 0 Answers
UI button not working 1 Answer