简体   繁体   English

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

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

I have an small 3d game with a ball that are going only in front and jump.我有一个小型 3d 游戏,它的球只能在前面并跳跃。 I want to stop the player movement when the ball are falling down but i don't know.我想在球落下时停止球员的移动,但我不知道。

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

}

Try to use condition to check if the movement of the ball before moving the player.尝试在移动球员之前使用条件检查球是否移动。

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

}

Worked with this code, thanks:使用此代码,谢谢:

 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