移动、鼠标观察和重力有效,但跳跃无效

问题描述

几个月前,我开始使用 Unity 创建游戏,并且刚刚切换到新的 Unity 输入系统,我的 Unity 编辑器版本是 2019.4.22f。我正在使用教程并为鼠标外观和运动,跳跃和重力编写脚本。我编写了 mouselook 脚本,它运行良好。然后我还完成了 Player Controller Script 的编写并对其进行了测试,移动、鼠标外观和 Gravity 的工作很吸引人,但随后跳跃就不行了,我尝试了其他教程并重复了同样的事情。现在,我尝试仅使用输入系统来执行此操作,因为之前我在项目设置的播放器选项中使用“两者”选项。我也没有任何控制台警告或错误。有没有人有解决方案或这个问题?

using UnityEngine;
 
public class Movement : MonoBehavIoUr {
 
    [Serializefield] CharacterController controller;
    [Serializefield] float speed = 11f;
    Vector2 horizontalInput;
 
    [Serializefield] float jumpHeight = 3.5f;
    bool jump;
 
    [Serializefield] float gravity = -30f; // -9.81
    Vector3 verticalVeLocity = Vector3.zero;
    [Serializefield] LayerMask groundMask;
    bool isGrounded;
 
    private void Update ()
    {
        isGrounded = Physics.CheckSphere(transform.position,0.1f,groundMask);
        if (isGrounded) {
            verticalVeLocity.y = 0;
        }
 
        Vector3 horizontalVeLocity = (transform.right * horizontalInput.x + transform.forward * horizontalInput.y) * speed;
        controller.Move(horizontalVeLocity * Time.deltaTime);
 
        // Jump: v = sqrt(-2 * jumpHeight * gravity)
        if (jump) {
            if (isGrounded) {
                verticalVeLocity.y = Mathf.Sqrt(-2f * jumpHeight * gravity);
                Debug.Log("isGrounded");
            }
            jump = false;
        }
 
        verticalVeLocity.y += gravity * Time.deltaTime;
        controller.Move(verticalVeLocity * Time.deltaTime);
    }
 
    public void ReceiveInput (Vector2 _horizontalInput)
    {
        horizontalInput = _horizontalInput;
    }
 
    public void OnJumppressed ()
    {
        jump = true;
    }
 
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)