기본 애니메이션 및 컨트롤러 추가
kaykit 애셋 일부 적용
This commit is contained in:
40
Assets/Scripts/Player/PlayerAnimationController.cs
Normal file
40
Assets/Scripts/Player/PlayerAnimationController.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerAnimationController : MonoBehaviour
|
||||
{
|
||||
private Animator animator;
|
||||
private CharacterController controller;
|
||||
|
||||
void Start()
|
||||
{
|
||||
animator = GetComponent<Animator>();
|
||||
controller = GetComponent<CharacterController>();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
// 1. 이동 속도 제어 (수평 속도만 계산)
|
||||
// Y축(중력/점프)을 제외한 X, Z축의 속도만 추출하여 MoveSpeed에 전달합니다.
|
||||
Vector3 horizontalVelocity = new Vector3(controller.velocity.x, 0, controller.velocity.z);
|
||||
float currentSpeed = horizontalVelocity.magnitude;
|
||||
|
||||
// 애니메이터의 MoveSpeed 파라미터 업데이트 (0.1은 보정값)
|
||||
animator.SetFloat("MoveSpeed", currentSpeed > 0.1f ? currentSpeed : 0f);
|
||||
|
||||
// 2. 점프 및 공중 상태 (isGrounded 활용)
|
||||
// CharacterController가 바닥에 닿아있는지 여부를 직접 전달합니다.
|
||||
animator.SetBool("isGrounded", controller.isGrounded);
|
||||
|
||||
// 3. 공격 (트리거)
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
animator.SetTrigger("Attack");
|
||||
}
|
||||
|
||||
// 4. 인터랙션 (트리거)
|
||||
if (Input.GetKeyDown(KeyCode.E))
|
||||
{
|
||||
animator.SetTrigger("Interact");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user