-
-
Save todorok1/4176c28e3e77556b5ed30285f9b50b5f to your computer and use it in GitHub Desktop.
シンプルRPGチュートリアル第6回 操作キャラクターの移動を制御するクラス
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Update() | |
{ | |
CheckMoveInput(); | |
} | |
/// * 中略 * /// | |
/// <summary> | |
/// キー入力を確認します。 | |
/// </summary> | |
void CheckMoveInput() | |
{ | |
// 既に移動中の場合は移動キーの入力を確認せず抜けます。 | |
if (_isMoving) | |
{ | |
return; | |
} | |
var moveDirection = Vector2Int.zero; | |
MoveAnimationDirection animDirection = MoveAnimationDirection.Front; | |
// 斜め移動は行わないため、上下左右のいずれかを移動対象とします。 | |
if (Input.GetKey(KeyCode.DownArrow)) | |
{ | |
moveDirection = Vector2Int.down; | |
animDirection = MoveAnimationDirection.Front; | |
} | |
else if (Input.GetKey(KeyCode.RightArrow)) | |
{ | |
moveDirection = Vector2Int.right; | |
animDirection = MoveAnimationDirection.Right; | |
} | |
else if (Input.GetKey(KeyCode.UpArrow)) | |
{ | |
moveDirection = Vector2Int.up; | |
animDirection = MoveAnimationDirection.Back; | |
} | |
else if (Input.GetKey(KeyCode.LeftArrow)) | |
{ | |
moveDirection = Vector2Int.left; | |
animDirection = MoveAnimationDirection.Left; | |
} | |
MovePlayer(moveDirection, animDirection); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment