56 lines
1.9 KiB
C#
56 lines
1.9 KiB
C#
using UnityEngine;
|
|
|
|
public class PlayerMovement : MonoBehaviour
|
|
{
|
|
[Header("--- 참조 ---")]
|
|
[SerializeField] private Stats stats;
|
|
[SerializeField] private PlayerHealth health;
|
|
[SerializeField] private PlayerAnimator pAnim;
|
|
[SerializeField] private PlayerAttack attackScript;
|
|
|
|
[Header("--- 차징 감속 설정 ---")]
|
|
[Range(0.1f, 1f)]
|
|
[SerializeField] private float minSpeedMultiplier = 0.3f;
|
|
|
|
private Vector3 _moveDir;
|
|
private bool _isSprinting;
|
|
|
|
public void SetMoveInput(Vector3 dir, bool sprint) { _moveDir = dir; _isSprinting = sprint; }
|
|
|
|
private void Update()
|
|
{
|
|
// 1. 💀 사망 시 혹은 ⚔️ 공격 중일 때 이동 차단
|
|
if (health != null && health.IsDead)
|
|
{
|
|
if (pAnim != null) pAnim.UpdateMove(0f);
|
|
return;
|
|
}
|
|
|
|
// ⭐ [추가] 공격 중(콤보 및 후딜레이 포함)에는 이동 입력 무시
|
|
if (attackScript != null && attackScript.IsAttacking)
|
|
{
|
|
if (pAnim != null) pAnim.UpdateMove(0f); // 제자리 대기 애니메이션 유도
|
|
return;
|
|
}
|
|
|
|
// 2. 이동 속도 계산 및 차징 감속 적용
|
|
float speed = _isSprinting ? stats.CurrentRunSpeed : stats.CurrentMoveSpeed;
|
|
|
|
if (attackScript != null && attackScript.IsCharging)
|
|
{
|
|
float speedReduction = Mathf.Lerp(1.0f, minSpeedMultiplier, attackScript.ChargeProgress);
|
|
speed *= speedReduction;
|
|
}
|
|
|
|
// 3. 실제 이동 처리
|
|
transform.Translate(_moveDir * speed * Time.deltaTime, Space.World);
|
|
|
|
// 4. 애니메이션 연동
|
|
if (pAnim != null)
|
|
{
|
|
float animVal = _moveDir.magnitude > 0.1f ? (_isSprinting ? 1.0f : 0.5f) : 0f;
|
|
if (attackScript != null && attackScript.IsCharging) animVal *= 0.5f;
|
|
pAnim.UpdateMove(animVal);
|
|
}
|
|
}
|
|
} |