【问题标题】:Unity 3d C# Stop player movement on death (falling down)Unity 3d C#在死亡时停止玩家移动(跌倒)
【发布时间】:2021-03-23 02:02:00
【问题描述】:

我有一个小型 3d 游戏,其中一个球只能在前面移动并跳跃。我想在球落下时停止球员移动,但我不知道。

 void FixedUpdate()
{
  // Player movement
  rb.transform.Translate(0, 0, forwardForce * Time.deltaTime,);

  // What's happening when the ball fall down
  if (rb.position.y < -1f)
  {
    FindObjectOfType<GameManager>().EndGame();
  }

}

【问题讨论】:

    标签: c# unity3d game-development


    【解决方案1】:

    在移动玩家之前尝试使用条件检查球是否移动。

    void FixedUpdate()
    {
      // What's happening when the ball fall down
      if (!(rb.position.y < -1f))
      {
        // Player movement
        rb.transform.Translate(0, 0, forwardForce * Time.deltaTime,);
      } else
      {
        FindObjectOfType<GameManager>().EndGame();
      }
    
    }
    

    【讨论】:

      【解决方案2】:

      使用此代码,谢谢:

       if (rb.position.y > -1f)
        {
          // Player Movement
          rb.transform.Translate(0, 0, forwardForce * Time.deltaTime);
         }
        else
        {
          FindObjectOfType<GameManager>().EndGame();
        }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-10-24
        • 2021-02-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多