【发布时间】:2018-05-25 18:14:37
【问题描述】:
我一直在做一个 Unity 游戏项目,我的精灵只会向下和向右移动。这是我当前的脚本:
#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;
}
}
【问题讨论】:
标签: unity3d sprite unityscript