所以我一直在努力为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;
}
}