簡體   English   中英

Unity 3d C# 死亡時停止玩家移動(跌倒)

[英]Unity 3d C# Stop player movement on death (falling down)

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

}

嘗試在移動球員之前使用條件檢查球是否移動。

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

}

使用此代碼,謝謝:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM