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

Unity鼠标点击移动功能失效,ClickToMove方法未执行求助

Unity鼠标点击移动无响应排查方案
  • 检查Input System激活状态
    打开Edit > Project Settings > Player,在Other Settings的Active Input Handling选项中,确认设置为Input System Package (New)。新旧输入系统混用会导致输入事件无法触发。

  • 验证Custom Actions配置

    1. 打开你的Custom Actions输入资产,确认Move动作的绑定为Left Mouse Button,且动作的Action Type设置为Button。
    2. 在Player对象的PlayerController脚本Inspector面板中,确认已正确拖入Custom Actions实例,无空引用。
  • 检查输入事件订阅逻辑
    核对PlayerController脚本的输入订阅代码,确保包含以下关键逻辑:

    private CustomActions inputActions;
    
    private void Awake()
    {
        inputActions = new CustomActions();
        inputActions.Player.Move.performed += ctx => ClickToMove();
    }
    
    private void OnEnable()
    {
        inputActions.Player.Enable();
    }
    
    private void OnDisable()
    {
        inputActions.Player.Disable();
    }
    

    若遗漏OnEnable中启用输入动作的代码,或Awake中未正确绑定回调,会导致ClickToMove无法被触发。

  • 确认脚本与组件状态

    1. 检查Player对象上的PlayerController脚本处于启用状态(Inspector中脚本前的复选框已勾选)。
    2. 确认Nav Mesh Agent组件已启用,未被其他脚本禁用。
  • 调试输入事件

    1. 给Custom Actions的Move动作临时添加一个键盘按键绑定(如Space),测试按键是否能触发ClickToMove方法。若能触发,说明鼠标绑定存在问题;若不能,说明输入系统整体配置有误。
    2. 打开Window > Analysis > Input Debugger,点击左键时查看是否有对应的输入事件被捕获:
      • 有事件:问题出在脚本的输入订阅逻辑。
      • 无事件:输入绑定或系统配置存在问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.03 14:05:07