这是我在 YouTube 视频中遵循的代码,但它不起作用

-2 c# unity-game-engine

我按照这个YouTube 教程代码一直到 11:55 并完成了所有操作,但我遇到了两个错误:

当前上下文中不存在名称“Move”,并且方法必须具有返回类型。

这是混合树用动画移动角色的代码:

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    private Animator _animator;



    // Start is called before the first frame update
    void Start()
    {
        _animator = GetComponent<Animator>();

    }

    // Update is called once per frame
    void Update()
    {
        if (_animator == null) return;

        var x = Input.GetAxis("Horizontal");
        var y = Input.GetAxis("Vertical");

        Move(x, y);
    }
    private Move(float x, float y)
    {
        _animator.SetFloat("VelX", x);
        _animator.SetFloat("VelY", y);
    }

}
Run Code Online (Sandbox Code Playgroud)

Dan*_*all 6

改变这一行

private Move(float x, float y)
Run Code Online (Sandbox Code Playgroud)

看起来像

private void Move(float x, float y)
Run Code Online (Sandbox Code Playgroud)

问题是您没有为该方法指定返回类型。