Skip to content

Instantly share code, notes, and snippets.

@todorok1
Created January 1, 2025 13:21
Show Gist options
  • Save todorok1/4176c28e3e77556b5ed30285f9b50b5f to your computer and use it in GitHub Desktop.
Save todorok1/4176c28e3e77556b5ed30285f9b50b5f to your computer and use it in GitHub Desktop.
シンプルRPGチュートリアル第6回 操作キャラクターの移動を制御するクラス
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