74. HelloWorldにスクリプトを加えてみよう
74
⑤コードの内容を変更する
(めんどくさい人は下記をコピペ)
using UnityEngine;
using System.Collections;
!
public class Move : MonoBehaviour {
// Use this for initialization
void Start () {
}
// 移動スピード
public float speed = 1000;
// 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;
// 移動する向きとスピードを代入する
GetComponent<Rigidbody2D>().velocity = direction * speed;
}
}