所以我想让我的木板从A点移动到B点,然后在它到达 B 点时停止。我实现了do while loop,for-loop但不幸的是,每次我点击播放场景按钮时,Unity 都会冻结,知道为什么会发生这种情况吗?
public class movingplank : MonoBehaviour
{
public Rigidbody2D Rigidbody2d;
float x;
Vector2 ve = new Vector2();
// Use this for initialization
void Start ()
{
Rigidbody2d = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update ()
{
do
{ ve = Rigidbody2d.transform.position;
x = ve.x; // storing x component of my plank into float x
Rigidbody2d.velocity = new Vector2(1f, 0f);
} while (x <-4); // move plank till it reaches point B
}
}
倚天杖
相关分类