1. 程式人生 > >Unity2D物件移動的幾種方法

Unity2D物件移動的幾種方法

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