Unity Roll A Ball 教程中的球不滚动

Ball not rolling in Unity Roll A Ball tutorial

我正在做滚球教程,但球不滚。我什至从网站上复制了代码,但仍然没有用。这是代码:

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

public class PlayerController : MonoBehaviour
{
    public float speed = 0;

    private Rigidbody rb;

    private float movementX;
    private float movementY;

    // Start is called before the first frame update
    void Start()
    {
        rb = GetComponent<Rigidbody>();
    }

    private void OnMove(InputValue movementValue)
    {
        Vector2 movementVector = movementValue.Get<Vector2>();

        movementX = movementVector.x;
        movementY = movementVector.y;
    }

    private void FixedUpdate()
    {
        Vector3 movement = new Vector3(movementX, 0.0f, movementY);

        rb.AddForce(movement * speed);
    }

}

谁能帮我解决这个问题?

这是我的第一个回答,如果不好,请见谅,但我们开始吧

您永远不会调用 OnMove 函数,因此 movementX 和 movementY 将始终未定义,因为它不是我所知道的内置函数。在获取你的运动矢量之前调用它,你应该被设置!干杯