You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Unity新输入系统鼠标点击无响应,键盘功能正常求助

Unity新输入系统鼠标点击无响应的解决方案

1. 检查Input Action绑定配置

  • 打开你的Input Action Asset,确认Button类型动作已正确绑定鼠标按键路径,比如<Mouse>/leftButton、<Mouse>/rightButton,避免只绑定键盘输入项。
  • 检查动作的Interaction设置,保持默认的Press即可,若改为Hold等其他类型会改变触发逻辑。

2. 确认Input System启用状态

  • 进入Project Settings > Player,将Active Input Handling设置为Input System Package (New),避免新旧输入系统冲突。
  • 场景中的EventSystem组件需替换为Input System UI Input Module,而非旧版的Standalone Input Module。

3. 确保Input Action处于激活状态

  • 在代码中主动激活对应的Action Map或单个动作,例如在Start()方法中添加:
    public InputAction mouseClickAction;
    public InputActionMap uiActionMap;
    
    void Start()
    {
        // 激活单个动作
        mouseClickAction.Enable();
        // 或激活整个动作组
        uiActionMap.Enable();
    }
    
  • 可修改测试代码查看动作状态,排查是否未激活:
    public void PrintVal(InputAction.CallbackContext context)
    {
        Debug.Log($"动作状态: {context.phase}");
        if (context.performed)
        {
            Debug.Log("检测到鼠标点击");
        }
    }
    
    若日志显示Disabled,则说明动作未激活。

4. 排查设备与Input Debugger问题

  • 打开Window > Analysis > Input Debugger,点击鼠标时查看Mouse设备的输入事件:
    • 若有输入信号但动作未响应,回到绑定配置检查路径是否正确;
    • 若无输入信号,尝试更新Unity Input System Package到最新稳定版,或更新鼠标驱动、重启设备。

5. 验证事件系统回调绑定

  • 若通过UI元素绑定回调,确认OnClick事件关联的是正确的Input Action触发逻辑;
  • 若通过代码绑定回调,确保注册逻辑正确:
    void OnEnable()
    {
        mouseClickAction.performed += PrintVal;
    }
    
    void OnDisable()
    {
        mouseClickAction.performed -= PrintVal;
    }
    

内容的提问来源于stack exchange,提问作者Sami Rehman

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 07:32:16