From 8790e3982a79c30beae06d22208c4df17907939e Mon Sep 17 00:00:00 2001 From: Mingu Kim Date: Fri, 22 Aug 2025 21:23:07 +0900 Subject: [PATCH] =?UTF-8?q?Player=EA=B0=80=20=EC=9E=90=EC=8B=9D=20?= =?UTF-8?q?=EC=98=A4=EB=B8=8C=EC=A0=9D=ED=8A=B8=EA=B9=8C=EC=A7=80=20?= =?UTF-8?q?=EC=98=A4=EB=A5=B8=EC=AA=BD(=EC=8A=A4=ED=94=84=EB=9D=BC?= =?UTF-8?q?=EC=9D=B4=ED=8A=B8=EB=A5=BC=20=EA=B0=95=EC=A0=9C=EB=A1=9C=20?= =?UTF-8?q?=EC=A2=8C=EC=9A=B0=20=EB=B0=98=EC=A0=84=20=EC=8B=9C=EC=BC=B0?= =?UTF-8?q?=EC=9D=84=20=EB=95=8C=20=EC=BD=9C=EB=9D=BC=EC=9D=B4=EB=8D=94?= =?UTF-8?q?=EA=B0=80=20=EB=B0=98=EB=8C=80=EB=A1=9C=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=EB=90=98=EC=96=B4=20=EC=88=98=EC=A0=95)=EC=9D=84=20=EB=B0=94?= =?UTF-8?q?=EB=9D=BC=EB=B3=BC=20=EC=88=98=20=EC=9E=88=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scenes/SampleScene.unity | 4 ++-- Assets/Scripts/Player/PlayerMove.cs | 12 +++++++++++- Assets/Scripts/Player/StateMachine.cs | 10 ++++++++-- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index eadea03b..fd879fa6 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -4408,7 +4408,7 @@ SpriteRenderer: m_SortingOrder: 0 m_Sprite: {fileID: 656402497436179863, guid: 0649d1685c554fb40869aba923cb5af0, type: 3} m_Color: {r: 1, g: 1, b: 1, a: 1} - m_FlipX: 1 + m_FlipX: 0 m_FlipY: 0 m_DrawMode: 0 m_Size: {x: 0.67, y: 1.36} @@ -6057,7 +6057,7 @@ SpriteRenderer: m_SortingOrder: 0 m_Sprite: {fileID: 442912304861412527, guid: 0649d1685c554fb40869aba923cb5af0, type: 3} m_Color: {r: 1, g: 1, b: 1, a: 1} - m_FlipX: 1 + m_FlipX: 0 m_FlipY: 0 m_DrawMode: 0 m_Size: {x: 2.1, y: 1.03} diff --git a/Assets/Scripts/Player/PlayerMove.cs b/Assets/Scripts/Player/PlayerMove.cs index 27891885..f713f09a 100644 --- a/Assets/Scripts/Player/PlayerMove.cs +++ b/Assets/Scripts/Player/PlayerMove.cs @@ -26,7 +26,7 @@ public class PlayerMove : MonoBehaviour RigidBody = GetComponent(); SpriteRenderer = GetComponent(); Animator = GetComponent(); - + // Null 체크 추가 if (RigidBody == null || SpriteRenderer == null || Animator == null) { @@ -36,12 +36,22 @@ public class PlayerMove : MonoBehaviour return; } + // 캐릭터의 기본 방향을 오른쪽으로 설정 + Vector3 initialScale = transform.localScale; + initialScale.x = -1f; + transform.localScale = initialScale; + _stateMachine = new StateMachine(State.IDLE, this); // 공격 콜라이더 참조 attackCollider = GetComponentInChildren(); } + void Start() + { + + } + private void Update() { _stateMachine.Update(); diff --git a/Assets/Scripts/Player/StateMachine.cs b/Assets/Scripts/Player/StateMachine.cs index 427802e7..2442ac1d 100644 --- a/Assets/Scripts/Player/StateMachine.cs +++ b/Assets/Scripts/Player/StateMachine.cs @@ -121,7 +121,11 @@ public class MoveState : IState float horizontalInput = Input.GetAxisRaw("Horizontal"); if (horizontalInput != 0) { - _player.SpriteRenderer.flipX = horizontalInput > 0; + // transform.localScale.x를 사용하여 캐릭터와 자식 오브젝트를 함께 뒤집습니다. + // 기본 스프라이트가 왼쪽을 바라보고 있으므로, 오른쪽 이동 시 x 스케일을 뒤집어야 합니다. + Vector3 newScale = _player.transform.localScale; + newScale.x = horizontalInput > 0 ? -1f : 1f; + _player.transform.localScale = newScale; } _player.RigidBody.AddForce(Vector2.right * horizontalInput * _player.maxSpeed, ForceMode2D.Force); @@ -170,7 +174,9 @@ public class JumpState : IState { if (Input.GetButton("Horizontal")) { - _player.SpriteRenderer.flipX = Input.GetAxisRaw("Horizontal") > 0; + Vector3 newScale = _player.transform.localScale; + newScale.x = Input.GetAxisRaw("Horizontal") > 0 ? -1f : 1f; + _player.transform.localScale = newScale; } }