플레이어 체력 감소, 점프, 달리기, 피격 상태 추가

This commit is contained in:
Mingu Kim
2025-07-18 20:43:37 +09:00
parent e78c902ee1
commit 425d98c653
2 changed files with 31 additions and 16 deletions

View File

@@ -1025,9 +1025,9 @@ GameObject:
- component: {fileID: 313304223}
- component: {fileID: 313304222}
- component: {fileID: 313304221}
m_Layer: 0
m_Layer: 8
m_Name: break_floor_0009_a1_0
m_TagString: Untagged
m_TagString: Platform
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
@@ -2331,7 +2331,7 @@ GameObject:
- component: {fileID: 1008441676}
- component: {fileID: 1008441675}
- component: {fileID: 1008441677}
m_Layer: 0
m_Layer: 10
m_Name: Player
m_TagString: Player
m_Icon: {fileID: 0}
@@ -2550,9 +2550,9 @@ GameObject:
m_Component:
- component: {fileID: 1133366867}
- component: {fileID: 1133366866}
m_Layer: 0
m_Layer: 8
m_Name: Grid
m_TagString: Untagged
m_TagString: Platform
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
@@ -2688,7 +2688,7 @@ GameObject:
- component: {fileID: 1794081151}
- component: {fileID: 1794081150}
- component: {fileID: 1794081152}
m_Layer: 0
m_Layer: 9
m_Name: Enemy
m_TagString: Enemy
m_Icon: {fileID: 0}
@@ -2879,7 +2879,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!212 &1991645575
SpriteRenderer:
m_ObjectHideFlags: 0
@@ -2975,7 +2975,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2119498364}
serializedVersion: 2
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
@@ -3028,7 +3028,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: 0
m_FlipX: 1
m_FlipY: 0
m_DrawMode: 0
m_Size: {x: 2.1, y: 1.03}

View File

@@ -7,7 +7,7 @@ public class PlayerMove : MonoBehaviour
Rigidbody2D _rigidBody;
SpriteRenderer _spriteRenderer;
// TODO : 점프, 공격, 돌진, 슈퍼 대시
// TODO : 점프, 공격, 돌진, 슈퍼 대시
Animator _animator;
// 변수
@@ -24,10 +24,11 @@ public class PlayerMove : MonoBehaviour
private void Update()
{
// 점프
if (Input.GetButtonDown("Jump"))
// 점프 ( 연속 점프 방지 )
if (Input.GetButtonDown("Jump") && _animator.GetBool("isJumping") == false)
{
_rigidBody.AddForce(Vector2.up * jumpPower, ForceMode2D.Impulse);
_animator.SetBool("isJumping", true);
}
// 키 입력 땔때 캐릭터 멈춤
@@ -41,6 +42,16 @@ public class PlayerMove : MonoBehaviour
{
_spriteRenderer.flipX = Input.GetAxisRaw("Horizontal") >= 1;
}
// 애니메이션 설정
if (MathF.Abs(_rigidBody.linearVelocity.x) < 0.5)
{
_animator.SetBool("isMoveing", false);
}
else
{
_animator.SetBool("isMoveing", true);
}
}
void FixedUpdate()
@@ -60,14 +71,16 @@ public class PlayerMove : MonoBehaviour
}
// 플랫폼을 밟고 있을 때
if (_rigidBody.linearVelocityY < 0)
if (_rigidBody.linearVelocity.y < 0)
{
Debug.DrawRay(_rigidBody.position, Vector2.down, Color.red);
RaycastHit2D rayHit = Physics2D.Raycast(_rigidBody.position, Vector2.down, 0.1f);
Debug.DrawRay(_rigidBody.position, Vector3.down, Color.green);
RaycastHit2D rayHit = Physics2D.Raycast(_rigidBody.position, Vector3.down, 1, LayerMask.GetMask("Platform"));
if(rayHit.collider != null)
{
// // 바닥에 닿아있을 때 애니메이션 변경
if(rayHit.distance < 0.5f)
if(rayHit.distance < 0.7f)
{
_animator.SetBool("isJumping", false);
}
@@ -94,6 +107,8 @@ public class PlayerMove : MonoBehaviour
// 플레이어 HP 감소
hp--;
Debug.Log(hp);
// 무적 표시
_spriteRenderer.color = new Color(1,1,1,0.5f); // 플레이어 반투명