Projext/Assets/5.TestScript/PlayerMovement.cs
2026-01-29 15:58:38 +09:00

35 lines
1.1 KiB
C#

using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
[SerializeField] private Stats stats;
[SerializeField] private PlayerHealth health;
[SerializeField] private PlayerAnimator pAnim;
private Vector3 _moveDir;
private bool _isSprinting;
public void SetMoveInput(Vector3 dir, bool sprint) { _moveDir = dir; _isSprinting = sprint; }
private void Update()
{
// 💀 사망 시 모든 이동 및 애니메이션 중단
if (health != null && health.IsDead)
{
if (pAnim != null) pAnim.UpdateMove(0f);
return;
}
// 이동 처리
float speed = _isSprinting ? stats.CurrentRunSpeed : stats.CurrentMoveSpeed;
transform.Translate(_moveDir * speed * Time.deltaTime, Space.World);
// ⭐ 애니메이션 연동: Speed 값 전송 (0:정지, 0.5:걷기, 1.0:뛰기)
if (pAnim != null)
{
// 입력이 있을 때만 0.5(걷기) 또는 1.0(뛰기) 전송
float animVal = _moveDir.magnitude > 0.1f ? (_isSprinting ? 1.0f : 0.5f) : 0f;
pAnim.UpdateMove(animVal);
}
}
}