Player가 자식 오브젝트까지 오른쪽(스프라이트를 강제로 좌우 반전 시켰을 때 콜라이더가 반대로 생성되어 수정)을 바라볼 수 있도록 코드 수정
This commit is contained in:
@@ -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}
|
||||
|
||||
@@ -26,7 +26,7 @@ public class PlayerMove : MonoBehaviour
|
||||
RigidBody = GetComponent<Rigidbody2D>();
|
||||
SpriteRenderer = GetComponent<SpriteRenderer>();
|
||||
Animator = GetComponent<Animator>();
|
||||
|
||||
|
||||
// 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<Collider2D>();
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
_stateMachine.Update();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user