1
votes

I have been trying for several hours to fix a button for a group project with no luck. I have the basics such as the object being a child of the canvas, graphics raycaster, button script, event system, etc.

There is no code going into this at the moment. Everything is done strictly with Unity's canvas and buttons. Upon clicking, the image should disappear, but it doesn't. The event handler does not register anything when the mouse hovers over the image.

I have looked through several posts on the Unity forum to try and find an answer that would work and none have helped.

2
Your first and third images are the same image. - Draco18s no longer trusts SE
@Draco18s Whoops. Alright, I fixed it. - Prstorero
Hmm. I've never tried using the builtin methods as the target function for the button click event. I am not sure that doing that works. I'd create a script with a zero-parameter function that sets the GO disabled, targetting that method instead. - Draco18s no longer trusts SE
@Draco18s While that could be a problem, the event system doesn't even detect when the mouse is over the image. So whether I use the built in method or my own right now, neither would work at the moment. - Prstorero
Oh! Your canvas is a child of another canvas. That really messes with the raycasting the mouse does. Last I mucked about with it I was getting clicks on both though... - Draco18s no longer trusts SE

2 Answers

1
votes

The problem was I needed to attach a camera that would be looking at the canvas to the "event camera" of the canvas component. This can be seen in the below image.

Image showing where to attach a camera

0
votes

In my case, I had rotated the image (on Canvas) to 180 degree and was trying to perform click which did not work. But as soon as I set the rotation to 0 degree the mouse click detection started working.