0

我有一个小型 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();
  }

}
4

2 回答 2

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();
  }

}
于 2021-03-23T03:11:34.843 回答
0

使用此代码,谢谢:

 if (rb.position.y > -1f)
  {
    // Player Movement
    rb.transform.Translate(0, 0, forwardForce * Time.deltaTime);
   }
  else
  {
    FindObjectOfType<GameManager>().EndGame();
  }
于 2021-03-23T14:15:30.270 回答