虽然我知道围绕C#的方式,但我很擅长在游戏开发和Unity中使用它。我想让球上下跳动。我可以轻松地让球左右移动,但是当我将代码从'滚动'改为'反弹'时,我得到以下结果:(球对角线不上下)
但我想要的是:
// Update is called once per frame
void Update () {
if (moveDown) {
transform.localScale = new Vector3 (-1f, 1f, 1f);
GetComponent<Rigidbody2D> ().velocity = new Vector2 (speed, GetComponent<Rigidbody2D> ().velocity.x);
} else {
transform.localScale = new Vector3 (1f, 1f, 1f);
GetComponent<Rigidbody2D> ().velocity = new Vector2 (-speed, GetComponent<Rigidbody2D> ().velocity.x);
}
}
我确信答案一定很简单,但经过漫长的一天,我的大脑已经糊里糊涂了。任何人都可以建议吗?
从左到右工作的代码是这样的:
transform.localScale = new Vector3 (-1f, 1f, 1f);
GetComponent<Rigidbody2D> ().velocity = new Vector2 (speed, GetComponent<Rigidbody2D> ().velocity.y);