転職を繰り返したサラリーマンの多趣味ブログ

30才未経験でSEに転職した人の多趣味ブログ

【Unity】GameObjectをキーボードで操作する方法②

public float speed = 10;

Rigidbody rb;

void Start () {

    rb = GetComponent<Rigidbody>();

}
	
// 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;
    rb.velocity = direction * speed;
        
}