1.改变对象速度
rb = GetComponent<Rigidbody2D>();
if (Input.GetKey(KeyCode.LeftArrow)) { rb.velocity = new Vector2(-movespeed, rb.velocity.y); } if (Input.GetKey(KeyCode.RightArrow)) { rb.velocity = new Vector2(movespeed, rb.velocity.y); }
1.改变对象速度
rb = GetComponent<Rigidbody2D>();