Unity Canvas button not working

2020-02-29 10:11发布

I added a canvas component to one of my images to override default layer order sorting. Turns out the button controls on that panel have stopped working?

Has anyone any idea about this in Unity? I am using unity 5.5.2.

2条回答
家丑人穷心不美
2楼-- · 2020-02-29 10:40

Turns out I did not know that you have add a Graphic Raycaster component as well. Started taking input after that.

Thanks everyone.

查看更多
看我几分像从前
3楼-- · 2020-02-29 10:52

The easiest way to debug is to :

  1. Run the game in the editor, not in full screen (uncheck Maximize On Play button)
  2. Select the EventSystem GameObject of your scene
  3. In the inspector, open the Preview Window and make it big enough
  4. Move your mouse on your screen, and check if the name of your buttons appear next to the field pointerEnter

EventSystem

If you can't see it, here are possible solutions :

  1. Make sure you don't have any UI elements above your button which could block the raycasts
  2. Make sure you have enabled raycasting on the images used by your buttons (check RaycastTarget)

Raycast target

  1. Make sure you have an EventSystem in your scene
  2. Make sure you have a callback attached to your buttons so as to trigger your functions
  3. Make sure you don't have any CanvasGroup with BlocksRaycast or Interactable set to false
  4. Make sure you have a GraphicRaycaster attached on a gameobject (on the Canvas usually)
查看更多
登录 后发表回答