diff --git a/Assets/InputSystem_Actions.inputactions b/Assets/InputSystem_Actions.inputactions index 8865bc65..14a71e38 100644 --- a/Assets/InputSystem_Actions.inputactions +++ b/Assets/InputSystem_Actions.inputactions @@ -36,7 +36,7 @@ "name": "Interact", "type": "Button", "id": "852140f2-7766-474d-8707-702459ba45f3", - "expectedControlType": "Button", + "expectedControlType": "", "processors": "", "interactions": "Hold", "initialStateCheck": false @@ -45,7 +45,7 @@ "name": "Crouch", "type": "Button", "id": "27c5f898-bc57-4ee1-8800-db469aca5fe3", - "expectedControlType": "Button", + "expectedControlType": "", "processors": "", "interactions": "", "initialStateCheck": false @@ -54,7 +54,7 @@ "name": "Jump", "type": "Button", "id": "f1ba0d36-48eb-4cd5-b651-1c94a6531f70", - "expectedControlType": "Button", + "expectedControlType": "", "processors": "", "interactions": "", "initialStateCheck": false @@ -63,7 +63,7 @@ "name": "Previous", "type": "Button", "id": "2776c80d-3c14-4091-8c56-d04ced07a2b0", - "expectedControlType": "Button", + "expectedControlType": "", "processors": "", "interactions": "", "initialStateCheck": false @@ -72,7 +72,7 @@ "name": "Next", "type": "Button", "id": "b7230bb6-fc9b-4f52-8b25-f5e19cb2c2ba", - "expectedControlType": "Button", + "expectedControlType": "", "processors": "", "interactions": "", "initialStateCheck": false diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index fd879fa6..5e0774a1 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -5990,12 +5990,12 @@ GameObject: - component: {fileID: 2119498366} - component: {fileID: 2119498367} m_Layer: 10 - m_Name: The Knight main sprites - atlas0 #00000357_482 + m_Name: AttackArea m_TagString: Player m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!4 &2119498365 Transform: m_ObjectHideFlags: 0 @@ -6096,7 +6096,7 @@ PolygonCollider2D: m_CallbackLayers: serializedVersion: 2 m_Bits: 4294967295 - m_IsTrigger: 0 + m_IsTrigger: 1 m_UsedByEffector: 0 m_CompositeOperation: 0 m_CompositeOrder: 0 diff --git a/Assets/Scripts/Player/PlayerMove.cs b/Assets/Scripts/Player/PlayerMove.cs index f713f09a..687e7b17 100644 --- a/Assets/Scripts/Player/PlayerMove.cs +++ b/Assets/Scripts/Player/PlayerMove.cs @@ -43,8 +43,17 @@ public class PlayerMove : MonoBehaviour _stateMachine = new StateMachine(State.IDLE, this); - // 공격 콜라이더 참조 - attackCollider = GetComponentInChildren(); + // AttackArea 게임 오브젝트를 찾고 그 자식에서 Collider2D를 가져옵니다. + Transform attackAreaTransform = transform.Find("AttackArea"); + if (attackAreaTransform != null) + { + attackCollider = attackAreaTransform.GetComponent(); + } + + if (attackCollider == null) + { + Debug.LogError("AttackArea child object or Collider2D component not found!"); + } } void Start() @@ -57,11 +66,6 @@ public class PlayerMove : MonoBehaviour _stateMachine.Update(); } - void FixedUpdate() - { - // FixedUpdate 로직은 이제 사용하지 않습니다. - } - void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.CompareTag("Enemy")) diff --git a/Assets/Scripts/Player/StateMachine.cs b/Assets/Scripts/Player/StateMachine.cs index 2442ac1d..48b33586 100644 --- a/Assets/Scripts/Player/StateMachine.cs +++ b/Assets/Scripts/Player/StateMachine.cs @@ -98,6 +98,10 @@ public class IdleState : IState { return State.MOVE; } + if (Input.GetMouseButtonDown(0)) + { + return State.Attack; + } return State.IDLE; } } @@ -151,6 +155,10 @@ public class MoveState : IState { return State.IDLE; } + if (Input.GetMouseButtonDown(0)) + { + return State.Attack; + } return State.MOVE; } } @@ -187,6 +195,10 @@ public class JumpState : IState public State CheckTransition() { + if (Input.GetMouseButtonDown(0)) + { + return State.Attack; + } if (_player.RigidBody.linearVelocity.y < 0) { Debug.DrawRay(_player.RigidBody.position, Vector3.down, Color.green); @@ -204,6 +216,8 @@ public class JumpState : IState public class AttackState : IState { private PlayerMove _player; + private float _attackDuration = 0.5f; // 공격 지속 시간 + private float _attackStartTime; public AttackState(PlayerMove player) { @@ -212,21 +226,30 @@ public class AttackState : IState public void Enter() { - _player.Animator.SetTrigger("Attack"); + // 애니메이션 없이 오브젝트만 활성화 + _player.attackCollider.gameObject.SetActive(true); + _attackStartTime = Time.time; } 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() { + _player.attackCollider.gameObject.SetActive(false); } public State CheckTransition() { - AnimatorStateInfo stateInfo = _player.Animator.GetCurrentAnimatorStateInfo(0); - if (stateInfo.normalizedTime >= 1.0f && !stateInfo.IsTag("Attack")) + if (Time.time >= _attackStartTime + _attackDuration) { return State.IDLE; }