首页 > 解决方案 > 短跑、跳跃和主菜单不起作用

问题描述

所以,我是一名使用 c# 和 Unity(刚开始)工作的游戏设计师,我有一个主菜单、冲刺和跳跃,但它们都不起作用。跳转一直有效,直到我制作了主菜单,而冲刺我无法开始工作。

const float walkSpeed = 6.0f;

  const float runSpeed = 11.0f;

  float moveSpeed = walkSpeed;

if (Input.GetKey(KeyCode.LeftShift))
      {
        Debug.Log("Run");
       // Set current speed to run if shift is down
       moveSpeed = runSpeed;
   }
   else {
       // Otherwise set current speed to walking speed
       moveSpeed = walkSpeed;

那是我的运行脚本,由于某种原因它不起作用,我不知道为什么,似乎它应该起作用。

if (Input.GetButtonDown("Jump"))
        {
          velocityY = jumpSpeed;
        }

      if(controller.isGrounded)
        {
          velocityY = 0.0f;
        }
      velocityY += gravity * Time.deltaTime;

那是我的跳跃/重力的东西

  public void PlayGame ()
  {
    SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
  }

  public void QuitGame ()
  {
    Debug.Log("Quit");
    Application.Quit();
  }
}

我看不出如何链接菜单,但不知何故,在进入后,跳转停止工作。

标签: c#unity3d

解决方案


你可能想为 Run 做类似的事情。我不知道这是否应该起作用,或者它是否是最好的方法,但我认为它应该起作用。用 () 封装它

    if ( (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.D) ) && 
    Input.GetKeyDown(KeyCode.LeftShift) )
    {
        Debug.Log("Run");
        // Set current speed to run if shift is down
        moveSpeed = runSpeed;
    }
    else
    {
        // Otherwise set current speed to walking speed
        moveSpeed = walkSpeed;
    }

推荐阅读