AttackState 공격 시 공격 궤적 스프라이트 노출되도록 수

This commit is contained in:
Mingu Kim
2025-08-22 22:02:35 +09:00
parent 8790e3982a
commit 3e551e99d0
4 changed files with 45 additions and 18 deletions

View File

@@ -36,7 +36,7 @@
"name": "Interact", "name": "Interact",
"type": "Button", "type": "Button",
"id": "852140f2-7766-474d-8707-702459ba45f3", "id": "852140f2-7766-474d-8707-702459ba45f3",
"expectedControlType": "Button", "expectedControlType": "",
"processors": "", "processors": "",
"interactions": "Hold", "interactions": "Hold",
"initialStateCheck": false "initialStateCheck": false
@@ -45,7 +45,7 @@
"name": "Crouch", "name": "Crouch",
"type": "Button", "type": "Button",
"id": "27c5f898-bc57-4ee1-8800-db469aca5fe3", "id": "27c5f898-bc57-4ee1-8800-db469aca5fe3",
"expectedControlType": "Button", "expectedControlType": "",
"processors": "", "processors": "",
"interactions": "", "interactions": "",
"initialStateCheck": false "initialStateCheck": false
@@ -54,7 +54,7 @@
"name": "Jump", "name": "Jump",
"type": "Button", "type": "Button",
"id": "f1ba0d36-48eb-4cd5-b651-1c94a6531f70", "id": "f1ba0d36-48eb-4cd5-b651-1c94a6531f70",
"expectedControlType": "Button", "expectedControlType": "",
"processors": "", "processors": "",
"interactions": "", "interactions": "",
"initialStateCheck": false "initialStateCheck": false
@@ -63,7 +63,7 @@
"name": "Previous", "name": "Previous",
"type": "Button", "type": "Button",
"id": "2776c80d-3c14-4091-8c56-d04ced07a2b0", "id": "2776c80d-3c14-4091-8c56-d04ced07a2b0",
"expectedControlType": "Button", "expectedControlType": "",
"processors": "", "processors": "",
"interactions": "", "interactions": "",
"initialStateCheck": false "initialStateCheck": false
@@ -72,7 +72,7 @@
"name": "Next", "name": "Next",
"type": "Button", "type": "Button",
"id": "b7230bb6-fc9b-4f52-8b25-f5e19cb2c2ba", "id": "b7230bb6-fc9b-4f52-8b25-f5e19cb2c2ba",
"expectedControlType": "Button", "expectedControlType": "",
"processors": "", "processors": "",
"interactions": "", "interactions": "",
"initialStateCheck": false "initialStateCheck": false

View File

@@ -5990,12 +5990,12 @@ GameObject:
- component: {fileID: 2119498366} - component: {fileID: 2119498366}
- component: {fileID: 2119498367} - component: {fileID: 2119498367}
m_Layer: 10 m_Layer: 10
m_Name: The Knight main sprites - atlas0 #00000357_482 m_Name: AttackArea
m_TagString: Player m_TagString: Player
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 1 m_IsActive: 0
--- !u!4 &2119498365 --- !u!4 &2119498365
Transform: Transform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -6096,7 +6096,7 @@ PolygonCollider2D:
m_CallbackLayers: m_CallbackLayers:
serializedVersion: 2 serializedVersion: 2
m_Bits: 4294967295 m_Bits: 4294967295
m_IsTrigger: 0 m_IsTrigger: 1
m_UsedByEffector: 0 m_UsedByEffector: 0
m_CompositeOperation: 0 m_CompositeOperation: 0
m_CompositeOrder: 0 m_CompositeOrder: 0

View File

@@ -43,8 +43,17 @@ public class PlayerMove : MonoBehaviour
_stateMachine = new StateMachine(State.IDLE, this); _stateMachine = new StateMachine(State.IDLE, this);
// 공격 콜라이더 참조 // AttackArea 게임 오브젝트를 찾고 그 자식에서 Collider2D를 가져옵니다.
attackCollider = GetComponentInChildren<Collider2D>(); Transform attackAreaTransform = transform.Find("AttackArea");
if (attackAreaTransform != null)
{
attackCollider = attackAreaTransform.GetComponent<Collider2D>();
}
if (attackCollider == null)
{
Debug.LogError("AttackArea child object or Collider2D component not found!");
}
} }
void Start() void Start()
@@ -57,11 +66,6 @@ public class PlayerMove : MonoBehaviour
_stateMachine.Update(); _stateMachine.Update();
} }
void FixedUpdate()
{
// FixedUpdate 로직은 이제 사용하지 않습니다.
}
void OnCollisionEnter2D(Collision2D collision) void OnCollisionEnter2D(Collision2D collision)
{ {
if (collision.gameObject.CompareTag("Enemy")) if (collision.gameObject.CompareTag("Enemy"))

View File

@@ -98,6 +98,10 @@ public class IdleState : IState
{ {
return State.MOVE; return State.MOVE;
} }
if (Input.GetMouseButtonDown(0))
{
return State.Attack;
}
return State.IDLE; return State.IDLE;
} }
} }
@@ -151,6 +155,10 @@ public class MoveState : IState
{ {
return State.IDLE; return State.IDLE;
} }
if (Input.GetMouseButtonDown(0))
{
return State.Attack;
}
return State.MOVE; return State.MOVE;
} }
} }
@@ -187,6 +195,10 @@ public class JumpState : IState
public State CheckTransition() public State CheckTransition()
{ {
if (Input.GetMouseButtonDown(0))
{
return State.Attack;
}
if (_player.RigidBody.linearVelocity.y < 0) if (_player.RigidBody.linearVelocity.y < 0)
{ {
Debug.DrawRay(_player.RigidBody.position, Vector3.down, Color.green); Debug.DrawRay(_player.RigidBody.position, Vector3.down, Color.green);
@@ -204,6 +216,8 @@ public class JumpState : IState
public class AttackState : IState public class AttackState : IState
{ {
private PlayerMove _player; private PlayerMove _player;
private float _attackDuration = 0.5f; // 공격 지속 시간
private float _attackStartTime;
public AttackState(PlayerMove player) public AttackState(PlayerMove player)
{ {
@@ -212,21 +226,30 @@ public class AttackState : IState
public void Enter() public void Enter()
{ {
_player.Animator.SetTrigger("Attack"); // 애니메이션 없이 오브젝트만 활성화
_player.attackCollider.gameObject.SetActive(true);
_attackStartTime = Time.time;
} }
public void Update() public void Update()
{ {
float horizontalInput = Input.GetAxisRaw("Horizontal");
if (horizontalInput != 0)
{
Vector3 newScale = _player.transform.localScale;
newScale.x = horizontalInput > 0 ? -1f : 1f;
_player.transform.localScale = newScale;
}
} }
public void Exit() public void Exit()
{ {
_player.attackCollider.gameObject.SetActive(false);
} }
public State CheckTransition() public State CheckTransition()
{ {
AnimatorStateInfo stateInfo = _player.Animator.GetCurrentAnimatorStateInfo(0); if (Time.time >= _attackStartTime + _attackDuration)
if (stateInfo.normalizedTime >= 1.0f && !stateInfo.IsTag("Attack"))
{ {
return State.IDLE; return State.IDLE;
} }