所以我一直在努力爲Unity遊戲項目,我的精靈只會向下移動和向右。這裏是我當前的腳本:統一性對象Movment - 對象只變爲向下和向右?
#pragma strict
function Update(){
var ship = GetComponent(Rigidbody2D);
var speed = 10;
if(Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow)){
ship.velocity.y = speed;
}else {
ship.velocity.y = 0;
}
if(Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow)){
ship.velocity.x = -1 * speed;
}else {
ship.velocity.x = 0;
}
if(Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow)){
ship.velocity.y = -1 * speed;
}else {
ship.velocity.y = 0;
}
if(Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow)){
ship.velocity.x = speed;
}else {
ship.velocity.x = 0;
}
}