2026-01-29 06:58:38 +00:00
|
|
|
|
using UnityEngine;
|
2026-02-01 15:49:12 +00:00
|
|
|
|
|
2026-01-29 06:58:38 +00:00
|
|
|
|
public class PlayerInput : MonoBehaviour
|
|
|
|
|
|
{
|
2026-02-03 14:41:49 +00:00
|
|
|
|
// 다른 스크립트에게 명령을 내려야 하니, 미리 참조 시킴
|
|
|
|
|
|
[SerializeField] private PlayerHealth health; // 죽었는지 확인용
|
|
|
|
|
|
[SerializeField] private PlayerMovement movement; // 이동 명령용
|
|
|
|
|
|
[SerializeField] private PlayerAim aim; // 회전 명령용
|
|
|
|
|
|
[SerializeField] private PlayerInteraction interaction; // 아이템 줍기 명령용
|
2026-02-06 04:20:12 +00:00
|
|
|
|
[SerializeField] private PlayerAttack attack;
|
2026-02-03 14:41:49 +00:00
|
|
|
|
[SerializeField] private PlayerStatsUI statsUI; // UI 창 열기 명령용
|
2026-01-30 03:24:13 +00:00
|
|
|
|
|
2026-01-29 06:58:38 +00:00
|
|
|
|
private void Update()
|
|
|
|
|
|
{
|
2026-02-03 14:41:49 +00:00
|
|
|
|
// 1. 사망 체크
|
|
|
|
|
|
// 죽었는데 키보드 눌린다고 시체가 움직이면 안 되니까 아예 입력을 차단(return)함
|
2026-01-29 06:58:38 +00:00
|
|
|
|
if (health != null && health.IsDead) return;
|
2026-01-30 03:24:13 +00:00
|
|
|
|
|
2026-02-03 14:41:49 +00:00
|
|
|
|
// 2. UI 토글 (C키)
|
|
|
|
|
|
// 스탯 창을 껐다 켰다 함
|
2026-02-01 15:49:12 +00:00
|
|
|
|
if (Input.GetKeyDown(KeyCode.C) && statsUI != null) statsUI.ToggleWindow();
|
2026-01-30 03:24:13 +00:00
|
|
|
|
|
2026-02-03 14:41:49 +00:00
|
|
|
|
// 3. 이동 입력 감지
|
|
|
|
|
|
// GetAxisRaw를 쓴 이유: 0에서 1로 부드럽게 변하는 게 아니라,
|
|
|
|
|
|
// 키를 누르면 즉시 1, 떼면 0이 되어서 빠릿빠릿한 조작감을 줌
|
|
|
|
|
|
float h = Input.GetAxisRaw("Horizontal"); // A, D 키 (-1, 0, 1)
|
|
|
|
|
|
float v = Input.GetAxisRaw("Vertical"); // W, S 키 (-1, 0, 1)
|
|
|
|
|
|
bool sprint = Input.GetKey(KeyCode.LeftShift); // Shift 누르고 있나?
|
2026-02-01 15:49:12 +00:00
|
|
|
|
|
2026-02-03 14:41:49 +00:00
|
|
|
|
// 4. 이동 명령 하달
|
2026-02-01 15:49:12 +00:00
|
|
|
|
if (movement != null)
|
|
|
|
|
|
{
|
2026-02-03 14:41:49 +00:00
|
|
|
|
// 방향 벡터를 정규화(.normalized)해서 대각선 이동 시 빨라지는 걸 방지
|
|
|
|
|
|
// 그리고 달리기 여부(sprint)도 같이 넘겨줍니다.
|
2026-02-01 15:49:12 +00:00
|
|
|
|
movement.SetMoveInput(new Vector3(h, 0, v).normalized, sprint);
|
|
|
|
|
|
|
2026-02-03 14:41:49 +00:00
|
|
|
|
// ⭐ [추가] 스페이스바 누르면 대시 명령!
|
2026-02-01 15:49:12 +00:00
|
|
|
|
if (Input.GetKeyDown(KeyCode.Space)) movement.AttemptDash();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-03 14:41:49 +00:00
|
|
|
|
// 5. 마우스 회전 명령
|
|
|
|
|
|
// 캐릭터가 마우스 커서를 바라보게 합니다.
|
2026-01-29 06:58:38 +00:00
|
|
|
|
if (aim != null) aim.RotateTowardsMouse();
|
2026-02-03 14:41:49 +00:00
|
|
|
|
|
|
|
|
|
|
// 6. 상호작용 (F키)
|
|
|
|
|
|
// 바닥에 떨어진 무기를 줍기
|
2026-01-29 06:58:38 +00:00
|
|
|
|
if (Input.GetKeyDown(KeyCode.F) && interaction != null) interaction.TryInteract();
|
2026-01-30 03:24:13 +00:00
|
|
|
|
|
2026-02-03 14:41:49 +00:00
|
|
|
|
// 7. 공격 입력 (좌클릭/우클릭)
|
2026-01-29 06:58:38 +00:00
|
|
|
|
if (attack != null)
|
|
|
|
|
|
{
|
2026-02-03 14:41:49 +00:00
|
|
|
|
// 우클릭 꾹: 차징(모으기) 시작
|
2026-01-29 06:58:38 +00:00
|
|
|
|
if (Input.GetMouseButtonDown(1)) attack.StartCharging();
|
2026-02-03 14:41:49 +00:00
|
|
|
|
|
|
|
|
|
|
// 우클릭 뗌: 차징 취소 (공격 안 하고 캔슬)
|
2026-01-29 06:58:38 +00:00
|
|
|
|
if (Input.GetMouseButtonUp(1)) attack.CancelCharging();
|
2026-02-03 14:41:49 +00:00
|
|
|
|
|
|
|
|
|
|
// 좌클릭: 공격 시도
|
2026-01-29 06:58:38 +00:00
|
|
|
|
if (Input.GetMouseButtonDown(0))
|
|
|
|
|
|
{
|
2026-02-03 14:41:49 +00:00
|
|
|
|
// 만약 우클릭(방어/조준) 상태에서 좌클릭을 했다면? -> 투척(Release)
|
2026-01-29 06:58:38 +00:00
|
|
|
|
if (Input.GetMouseButton(1)) attack.ReleaseAttack();
|
2026-02-03 14:41:49 +00:00
|
|
|
|
// 그냥 좌클릭만 했다면? -> 일반 평타(Normal Attack)
|
2026-01-29 06:58:38 +00:00
|
|
|
|
else attack.PerformNormalAttack();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|