Unity UI 按钮对点击或悬停没有反应 [英] Unity UI button not reacting to clicks or hovering

查看:112
本文介绍了Unity UI 按钮对点击或悬停没有反应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Unity 3D 的新 UI 系统为我的游戏构建暂停菜单.目前我正在尝试让我的按钮响应鼠标点击.我的一些层次结构如下:

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:

我已经确保我的 Image 组件选中了Raycast target"并且我的 Button 组件选中了Interactable".

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

这可能是因为我的 Canvas 的渲染模式在屏幕空间(相机)中吗?我需要将渲染模式设置为此,因为我在游戏过程中在 UI 前面添加了 3D 模型.

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:

  • 确保存在 EventSystem
  • 检查另一个 UI 元素没有覆盖按钮,防止光线投射
  • 确保渲染 UI 的摄像头位于连接到播放器的主摄像头上方.渲染 UI 相机的图层为 1,而播放器相机的图层为 0.

推荐答案

您的 EventSystem 游戏对象缺少 Standalone Input Module 脚本组件.

Your EventSystem GameObject is missing the Standalone Input Module Script component.

选择您的 EventSystem->添加组件 ->独立输入模块.大功告成!

Select your EventSystem->Add Component ->Standalone Input Module. Done!

下面的 gif 描述了两种方法.

The gif below decsribes two ways to do that.

这篇关于Unity UI 按钮对点击或悬停没有反应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆