-
-
Save todorok1/887f918c4b68ad7c682f1f17dd640750 to your computer and use it in GitHub Desktop.
シンプルRPGチュートリアル第6回 操作キャラクターの移動を制御するクラス
This file contains hidden or 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
| /// <summary> | |
| /// 操作キャラクターを移動させます。 | |
| /// </summary> | |
| /// <param name="moveDirection">移動方向</param> | |
| /// <param name="animDirection">アニメーションの方向</param> | |
| void MovePlayer(Vector2Int moveDirection, MoveAnimationDirection animDirection) | |
| { | |
| if (moveDirection == Vector2Int.zero) | |
| { | |
| return; | |
| } | |
| _isMoving = true; | |
| // 論理的な座標から移動先の座標を計算し、ワールド座標に変換します。 | |
| _posOnTile += (Vector3Int)moveDirection; | |
| var targetWorldPos = _baseTilemap.CellToWorld(_posOnTile); | |
| targetWorldPos += _baseTilemap.tileAnchor; | |
| // 移動方向に応じたアニメーションに切り替えます。 | |
| if (_animator != null) | |
| { | |
| _animator.SetInteger(AnimationSettings.DirectionParameterName, (int)animDirection); | |
| } | |
| // コルーチンを使ってキャラクターのゲームオブジェクトを移動させます。 | |
| var sourcePos = gameObject.transform.position; | |
| StartCoroutine(MovePlayerProcess(sourcePos, targetWorldPos)); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment