I'm using Unity 3D's new UI system to build a pause menu for my game. Currently I'm trying to have my buttons respond to mouse clicks. Some of my hierarchy is as follows:
When I click on one of my buttons in-game nothing happens, this includes a lack of button animation that should occur when hovering. My "Main Canvas" gameobject contains the following components:
I have already ensured that my Image component has "Raycast target" checked and that my Button component has "Interactable" checked.
Could this be because my Canvas' render mode is in screen space (camera)? I need the render mode to be set to this because I have 3D models that are added in front of the UI during gameplay.
Things I have already tried / checked:
If we accidentally delete the GameObject EventSystem, the mouse inputs are not detected and the Canvas buttons do not work. To solve this we can create a second Canvas to make the EventSystem appear, then remove the second Canvas. Or we can simple create an EventSystem.
A button should only react once it is clicked, which is why it has the onclick . Unity is already internally checking if a button is clicked by using its EventSystem and a series of GraphicalRaycasts .
If the UI Layer is hidden, un-hide it. To do so just click on the Layers dropdown to the upper right of Unity's Editor and click on the layer you wish to un-hide.
Your EventSystem GameObject is missing the Standalone Input Module
Script component.
Select your EventSystem->Add Component ->Standalone Input Module
. Done!
The gif below decsribes two ways to do that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With