Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unity UI button not reacting to clicks or hovering

Tags:

unity3d

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:

Canvas hierarchy

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:

Canvas components

I have already ensured that my Image component has "Raycast target" checked and that my Button component has "Interactable" checked.

Button

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:

  • Ensured that an EventSystem was present
  • Checked that another UI element wasn't covering the buttons, preventing a raycast
  • Ensured that the camera rendering the UI is above my main camera that is attached to the player. The rendering UI camera has a layer of 1 while the player camera has a layer of 0.
like image 405
Walker Christie Avatar asked Jul 25 '16 03:07

Walker Christie


People also ask

Why are my Unity buttons not working?

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.

How do I check if a UI button is pressed in Unity?

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 .

Why is UI not showing up Unity?

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.


1 Answers

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.

enter image description here

like image 87
Programmer Avatar answered Mar 16 '23 18:03

Programmer