플레이어 체력 감소, 점프, 달리기, 피격 상태 추가
This commit is contained in:
@@ -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); // 플레이어 반투명
|
||||
|
||||
|
||||
Reference in New Issue
Block a user