Add speed scaling and slide groundwork
This commit is contained in:
@@ -9,16 +9,29 @@ public class PlayerController : MonoBehaviour {
|
||||
private bool isGrounded = false; // 바닥에 닿았는지 나타냄
|
||||
private bool isDead = false; // 사망 상태
|
||||
|
||||
private bool isSliding = false; // 슬라이딩 상태
|
||||
|
||||
private Rigidbody2D playerRigidbody; // 사용할 리지드바디 컴포넌트
|
||||
private Animator animator; // 사용할 애니메이터 컴포넌트
|
||||
private AudioSource playerAudio; // 사용할 오디오 소스 컴포넌트
|
||||
|
||||
private CapsuleCollider2D playerCollider; // 플레이어의 콜라이더 충돌 범위
|
||||
private Vector2 originalColliderSize; // 기본 자세일 때 콜라이더 크기
|
||||
private Vector2 originalColliderOffset; // 기본 자세일 때 콜라이더 중심 위치
|
||||
public Vector2 slidingColliderSize; // 슬라이딩 자세일 때 콜라이더 크기
|
||||
public Vector2 slidingColliderOffset; // 슬라이딩 자세일 때 콜라이더 중심 위치
|
||||
|
||||
private void Start() {
|
||||
// 게임 오브젝트로부터 사용할 컴포넌트들을 가져와 변수에 할당
|
||||
playerRigidbody = GetComponent<Rigidbody2D>();
|
||||
animator = GetComponent<Animator>();
|
||||
playerAudio = GetComponent<AudioSource>();
|
||||
}
|
||||
|
||||
// 게임 콜라이더를 가져와서 현 상태를 저장
|
||||
playerCollider = GetComponent<CapsuleCollider2D>();
|
||||
originalColliderSize = playerCollider.size;
|
||||
originalColliderOffset = playerCollider.offset;
|
||||
}
|
||||
|
||||
private void Update() {
|
||||
if(isDead)
|
||||
@@ -46,6 +59,16 @@ public class PlayerController : MonoBehaviour {
|
||||
}
|
||||
|
||||
animator.SetBool("Grounded", isGrounded);
|
||||
|
||||
// 마우스 오른쪽 버튼을 누르고 땅에 있는 상태이며 슬라이딩이 아닌 상태면 슬라이딩 작동
|
||||
if (Input.GetMouseButtonDown(1) && isGrounded && !isSliding)
|
||||
{
|
||||
StartSlide();
|
||||
}
|
||||
else if (Input.GetMouseButtonUp(1) && isSliding)
|
||||
{
|
||||
EndSlide();
|
||||
}
|
||||
}
|
||||
|
||||
private void Die() {
|
||||
@@ -83,4 +106,22 @@ public class PlayerController : MonoBehaviour {
|
||||
// 바닥에서 벗어났음을 감지하는 처리
|
||||
isGrounded = false;
|
||||
}
|
||||
|
||||
private void StartSlide()
|
||||
{
|
||||
isSliding = true;
|
||||
animator.SetBool("Sliding", true);
|
||||
|
||||
playerCollider.size = slidingColliderSize;
|
||||
playerCollider.offset = slidingColliderOffset;
|
||||
}
|
||||
|
||||
private void EndSlide()
|
||||
{
|
||||
isSliding = false;
|
||||
animator.SetBool("Sliding", false);
|
||||
|
||||
playerCollider.size = originalColliderSize;
|
||||
playerCollider.offset = originalColliderOffset;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user