public class movingPlayer: MonoBehaviour {
ย ย public float pSpeed = 5.0f;
ย ย private Vector2 direction;
ย ย // Use this for initialization
ย ย void Start ()
ย ย {
ย ย }
ย ย // Update is called once per frame
ย ย void Update ()
ย ย {
ย ย ย ย GetInput();
ย ย ย ย float h = Input.GetAxis("Horizontal");
ย ย ย ย float v = Input.GetAxis("Vertical");
ย ย ย ย h = pSpeed * Time.deltaTime;
ย ย ย ย v = pSpeed * Time.deltaTime;
ย ย ย ย transform.Translate(direction * h);
ย ย ย ย transform.Translate(direction * v);
ย ย }
ย ย private void GetInput()
ย ย {
ย ย ย ย direction = Vector2.zero;
ย ย ย ย if (Input.GetKey(KeyCode.W)) ;
ย ย ย ย {
ย ย ย ย ย ย direction += Vector2.up;
ย ย ย ย }
ย ย ย ย if (Input.GetKey(KeyCode.A)) ;
ย ย ย ย {
ย ย ย ย ย ย direction += Vector2.left;
ย ย ย ย }
ย ย ย ย if (Input.GetKey(KeyCode.S)) ;
ย ย ย ย {
ย ย ย ย ย ย direction += Vector2.down;
ย ย ย ย }
ย ย ย ย if (Input.GetKey(KeyCode.D)) ;
ย ย ย ย {
ย ย ย ย ย ย direction += Vector2.right;
ย ย ย ย }
ย ย }
}
์ ์๋๋์ง ๋ชจ๋ฅด๊ฒ ๋๊ฒ
1์ผ์ฐจ ๋๋ค๋ฅผ ๋์๋ฌ๋ผ
h ๋ v์ ์ธํ๋ฐ์๋๊ณ ๋ค์ ๋ค๋ฅธ๊ฑธ ๋ฐ์ผ๋ ์๋์ ์ํ์ง