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

如何在Unity中将PlayStation控制器的跳跃按键从方块改为X键?

把PlayStation控制器的跳跃键从方块键改成X键的具体操作

方法一:用Unity旧版Input Manager(默认自带)

  • 顶部菜单栏打开 Edit > Project Settings
  • 在左侧面板选择 Input Manager,找到Axes列表里的Jump项并展开
  • 修改Positive Button字段:
    • 要是只想用PS的X键,直接改成 joystick button 1(PS4/PS5控制器的X键对应此代码)
    • 想同时保留空格键和X键,就填 space, joystick button 1
  • 点击窗口右上角的Apply保存设置,之后用GetButtonDown("Jump")就能触发X键或空格键的跳跃了

方法二:用Unity新版Input System(官方推荐)

如果你之前尝试的是动作映射,大概率是用的新版系统,按下面步骤来:

  1. 导入新版Input System:
    • 顶部菜单打开 Window > Package Manager,搜索Input System并安装,安装后重启编辑器
  2. 创建输入动作资产:
    • 在Project窗口右键,选择Input Actions,命名比如PlayerControls,双击打开编辑界面
  3. 绑定跳跃键:
    • 找到(或新建)Jump动作:点界面左上角的+号,选Button类型,命名为Jump
    • 点击Jump右侧的Add Binding,在弹出的菜单里选PlayStation Controller > Button South(这就是PS的X键,对应通用的“确认键”)
    • 要保留空格键的话,再添一个绑定:选Keyboard > Space
    • 按Ctrl+S保存这个动作资产
  4. 在脚本里调用:
    替换原来的GetButtonDown("Jump")逻辑,示例代码:
    // 先声明输入动作变量
    private PlayerControls _playerControls;
    
    void Awake()
    {
        _playerControls = new PlayerControls();
    }
    
    void OnEnable()
    {
        // 启用跳跃动作
        _playerControls.Player.Jump.Enable();
    }
    
    void OnDisable()
    {
        // 禁用动作,避免内存泄漏
        _playerControls.Player.Jump.Disable();
    }
    
    void Update()
    {
        // 检测跳跃输入
        if (_playerControls.Player.Jump.WasPressedThisFrame())
        {
            // 这里写你的跳跃逻辑
            Jump();
        }
    }
    
    void Jump()
    {
        // 跳跃实现代码
    }
    
    也可以用PlayerInput组件可视化绑定:给玩家对象加PlayerInput组件,把PlayerControls拖到Actions字段,选好行为模式(比如Invoke Unity Events),直接在组件里关联跳跃方法,不用写上面的检测代码

小提示

  • 旧版Input Manager里的PS按键如果对应不对,可以写个测试脚本打印Input.GetKeyDown(KeyCode.JoystickButtonX)的值,逐个试哪个是X键
  • 新版Input System的Button South是通用键位,会自动适配不同控制器:PS是X,Xbox是A,Switch是B,不用单独改其他控制器的键位

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.02 10:25:20