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

Unity第一人称移动脚本CS1061错误求助

解决Unity第一人称移动的CS1061错误

错误1:'PlayerInput' 不包含 'Onfoot' 的定义

你混淆了Unity内置的PlayerInput组件,和通过Input System创建的自定义Input Action Asset生成的类,同时存在大小写拼写问题:

  • 教程里的OnFootActions应该来自你自己创建的Input Action Asset(比如命名为PlayerControls),而非Unity自带的PlayerInput类。把代码里的PlayerInput.OnFootActions改成你生成的类名,比如PlayerControls.OnFootActions。
  • 检查动作映射名称的大小写:如果教程里是OnFoot(首字母大写F),你写成了Onfoot(小写f),会导致找不到定义,必须和Input Action Asset里的名称完全一致。
  • 确认Input Action Asset已勾选“Generate C# Class”选项,这样才会生成可调用的Actions类。

修正示例(假设你的Input Action Asset叫PlayerControls):

// 替换原有的PlayerInput相关声明
private PlayerControls playerInput;
private PlayerControls.OnFootActions onFoot;

void Awake()
{
    playerInput = new PlayerControls();
    onFoot = playerInput.OnFoot; // 匹配动作映射的正确名称
}

错误2:'PlayerMotor' 不包含 'ProccessMove' 的定义

你的PlayerMotor类里没有实现ProccessMove方法(注意:大概率是拼写错误,教程里应该是ProcessMove),同时脚本里的private PlayerMotor motor;完全多余——当前脚本本身就是PlayerMotor实例,无需自己获取组件。

步骤1:添加ProcessMove方法

在PlayerMotor类中补充移动逻辑的方法:

// 在PlayerMotor类内添加该方法
public void ProcessMove(Vector2 input)
{
    // 示例移动逻辑(根据你的需求选择CharacterController或Rigidbody实现)
    Vector3 moveDirection = new Vector3(input.x, 0, input.y);
    // 若使用CharacterController:
    // GetComponent<CharacterController>().Move(moveDirection * Time.deltaTime * 5f);
    // 若使用Rigidbody:
    // GetComponent<Rigidbody>().velocity = moveDirection * 5f;
}

步骤2:修正FixedUpdate调用

删掉多余的motor变量,直接调用方法:

void FixedUpdate()
{
    ProcessMove(onFoot.Movement.ReadValue<Vector2>());
}

额外检查项

  1. 确保已通过Package Manager安装Unity Input System包。
  2. 确认你的Input Action Asset内存在OnFoot动作映射,且该映射下有绑定了WASD/方向键的Movement动作。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.14 03:55:29