Unity2D
キーボードの入力に応じて Direction を決定して、GameObject の velocity を変化させることで移動させる
public class Player : MonoBehaviour {
public float speed = 5;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
float x = Input.GetAxisRaw ("Horizontal");
float y = Input.GetAxisRaw ("Vertical");
Vector2 direction = new Vector2 (x, y).normalized;
rigidbody2D.velocity = direction * speed;
}
}