공격 스테이트 추가 + 플레이어가 우측으로 이동 하다 멈추면 왼쪽을 바라보는 문제 수정
This commit is contained in:
@@ -4542,6 +4542,7 @@ MonoBehaviour:
|
||||
maxSpeed: 5
|
||||
jumpPower: 10
|
||||
hp: 5
|
||||
attackCollider: {fileID: 2119498367}
|
||||
--- !u!1 &1010476769
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -5987,13 +5988,14 @@ GameObject:
|
||||
m_Component:
|
||||
- component: {fileID: 2119498365}
|
||||
- component: {fileID: 2119498366}
|
||||
- component: {fileID: 2119498367}
|
||||
m_Layer: 0
|
||||
m_Name: The Knight main sprites - atlas0 #00000357_482
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &2119498365
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -6064,6 +6066,94 @@ SpriteRenderer:
|
||||
m_WasSpriteAssigned: 1
|
||||
m_MaskInteraction: 0
|
||||
m_SpriteSortPoint: 0
|
||||
--- !u!60 &2119498367
|
||||
PolygonCollider2D:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2119498364}
|
||||
m_Enabled: 1
|
||||
serializedVersion: 3
|
||||
m_Density: 1
|
||||
m_Material: {fileID: 0}
|
||||
m_IncludeLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 0
|
||||
m_ExcludeLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 0
|
||||
m_LayerOverridePriority: 0
|
||||
m_ForceSendLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_ForceReceiveLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_ContactCaptureLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_CallbackLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_IsTrigger: 0
|
||||
m_UsedByEffector: 0
|
||||
m_CompositeOperation: 0
|
||||
m_CompositeOrder: 0
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_SpriteTilingProperty:
|
||||
border: {x: 0, y: 0, z: 0, w: 0}
|
||||
pivot: {x: 0.5, y: 0.5}
|
||||
oldSize: {x: 2.1, y: 1.03}
|
||||
newSize: {x: 2.1, y: 1.03}
|
||||
adaptiveTilingThreshold: 0.5
|
||||
drawMode: 0
|
||||
adaptiveTiling: 0
|
||||
m_AutoTiling: 0
|
||||
m_Points:
|
||||
m_Paths:
|
||||
- - {x: -0.35999998, y: -0.195}
|
||||
- {x: -0.47, y: -0.155}
|
||||
- {x: -0.62, y: -0.074999996}
|
||||
- {x: -0.68, y: 0.125}
|
||||
- {x: -0.53999996, y: 0.21499999}
|
||||
- {x: -0.41, y: 0.255}
|
||||
- {x: -0.39999998, y: 0.265}
|
||||
- {x: -0.37, y: 0.265}
|
||||
- {x: -0.31, y: 0.275}
|
||||
- {x: -0.38, y: 0.265}
|
||||
- {x: -0.39, y: 0.255}
|
||||
- {x: -0.47, y: 0.235}
|
||||
- {x: -0.53999996, y: 0.205}
|
||||
- {x: -0.61, y: 0.13499999}
|
||||
- {x: -0.64, y: 0.065}
|
||||
- {x: -0.59999996, y: -0.005}
|
||||
- {x: -0.57, y: 0.015}
|
||||
- {x: -0.52, y: 0.125}
|
||||
- {x: -0.31, y: 0.185}
|
||||
- {x: 0.04, y: 0.225}
|
||||
- {x: 0.78999996, y: 0.145}
|
||||
- {x: 0.84999996, y: 0.205}
|
||||
- {x: 0.84999996, y: 0.21499999}
|
||||
- {x: 0.83, y: 0.24499999}
|
||||
- {x: 0.57, y: 0.375}
|
||||
- {x: 0.28, y: 0.45499998}
|
||||
- {x: 0.04, y: 0.49499997}
|
||||
- {x: -0.35, y: 0.49499997}
|
||||
- {x: -0.53, y: 0.475}
|
||||
- {x: -0.76, y: 0.415}
|
||||
- {x: -0.88, y: 0.355}
|
||||
- {x: -1.03, y: 0.155}
|
||||
- {x: -1.03, y: -0.044999998}
|
||||
- {x: -0.95, y: -0.155}
|
||||
- {x: -0.78, y: -0.24499999}
|
||||
- {x: -0.53, y: -0.315}
|
||||
- {x: -0.22, y: -0.33499998}
|
||||
- {x: -0.07, y: -0.33499998}
|
||||
- {x: -0.04, y: -0.315}
|
||||
- {x: -0.03, y: -0.275}
|
||||
- {x: -0.08, y: -0.24499999}
|
||||
m_UseDelaunayMesh: 0
|
||||
--- !u!1 &2133490102
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@@ -17,6 +17,9 @@ public class PlayerMove : MonoBehaviour
|
||||
|
||||
private StateMachine _stateMachine;
|
||||
|
||||
// 공격 콜라이더
|
||||
public Collider2D attackCollider;
|
||||
|
||||
// 사용하는 컴포넌트들 초기화
|
||||
void Awake()
|
||||
{
|
||||
@@ -35,6 +38,9 @@ public class PlayerMove : MonoBehaviour
|
||||
}
|
||||
|
||||
_stateMachine = new StateMachine(State.IDLE, this);
|
||||
|
||||
// 공격 콜라이더 참조
|
||||
attackCollider = GetComponentInChildren<Collider2D>();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
@@ -76,4 +82,21 @@ public class PlayerMove : MonoBehaviour
|
||||
{
|
||||
// OffDamaged 로직은 DamagedState의 Exit()로 이동
|
||||
}
|
||||
|
||||
// 공격 애니메이션 이벤트에서 호출될 함수
|
||||
public void StartAttackHitbox()
|
||||
{
|
||||
if (attackCollider != null)
|
||||
{
|
||||
attackCollider.enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void EndAttackHitbox()
|
||||
{
|
||||
if (attackCollider != null)
|
||||
{
|
||||
attackCollider.enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ using UnityEngine;
|
||||
|
||||
public enum State
|
||||
{
|
||||
IDLE, MOVE, JUMP
|
||||
IDLE, MOVE, JUMP, Attack
|
||||
}
|
||||
|
||||
public class StateMachine
|
||||
@@ -116,8 +116,12 @@ public class MoveState : IState
|
||||
|
||||
public void Update()
|
||||
{
|
||||
// 상태별 로직
|
||||
_player.SpriteRenderer.flipX = Input.GetAxisRaw("Horizontal") > 0;
|
||||
float horizontalInput = Input.GetAxisRaw("Horizontal");
|
||||
if (horizontalInput != 0)
|
||||
{
|
||||
// 입력 방향에 따라 스프라이트를 뒤집음.
|
||||
_player.SpriteRenderer.flipX = horizontalInput > 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void Exit()
|
||||
@@ -189,7 +193,6 @@ public class JumpState : IState
|
||||
public class AttackState : IState
|
||||
{
|
||||
private PlayerMove _player;
|
||||
private IdleState _idleState;
|
||||
|
||||
public AttackState(PlayerMove player)
|
||||
{
|
||||
@@ -198,28 +201,35 @@ public class AttackState : IState
|
||||
|
||||
public void Enter()
|
||||
{
|
||||
|
||||
// 공격 애니메이션 시작
|
||||
_player.Animator.SetTrigger("Attack");
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
|
||||
// 공격 상태 로직 (예: 애니메이션 재생 중 다른 입력 무시)
|
||||
}
|
||||
|
||||
public void FixedUpdate()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Exit()
|
||||
{
|
||||
// _player.Animator.SetBool(PlayerMove.IsAttacking, false);
|
||||
// 공격 상태 종료
|
||||
}
|
||||
|
||||
public State CheckTransition()
|
||||
{
|
||||
// 공격이 종료됐을 때
|
||||
// idle
|
||||
// 공격 애니메이션이 끝나면 Idle 상태로 전환
|
||||
// Animator의 현재 상태를 확인하여 transition을 처리합니다.
|
||||
// 예를 들어, GetCurrentAnimatorStateInfo(0).IsName("Attack")이 false가 되면 전환
|
||||
// 또는 애니메이션 이벤트로 상태 전환을 직접 호출할 수도 있습니다.
|
||||
AnimatorStateInfo stateInfo = _player.Animator.GetCurrentAnimatorStateInfo(0);
|
||||
if (stateInfo.normalizedTime >= 1.0f && !stateInfo.IsTag("Attack"))
|
||||
{
|
||||
return State.IDLE;
|
||||
}
|
||||
return State.Attack;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user