Projext/Assets/Scripts/Player/Animation.cs

49 lines
3.3 KiB
C#
Raw Normal View History

2026-02-12 15:23:25 +00:00
using UnityEngine; // 유니티 엔진의 기본 기능을 불러올거에요 -> UnityEngine을
2026-01-29 06:58:38 +00:00
2026-02-12 15:23:25 +00:00
public class PlayerAnimator : MonoBehaviour // 클래스를 선언할거에요 -> MonoBehaviour를 상속받는 PlayerAnimator를
2026-01-29 06:58:38 +00:00
{
2026-02-12 15:23:25 +00:00
[SerializeField] private Animator anim; // 변수를 선언할거에요 -> 애니메이터 컴포넌트 anim을
[SerializeField] private PlayerHealth health; // 변수를 선언할거에요 -> 플레이어 체력 스크립트 health를
2026-01-29 06:58:38 +00:00
// ⭐ 추가: 진짜 공격 로직이 있는 스크립트 연결
2026-02-12 15:23:25 +00:00
[SerializeField] private PlayerAttack attack; // 변수를 선언할거에요 -> 플레이어 공격 스크립트 attack을
2026-01-29 06:58:38 +00:00
2026-02-12 15:23:25 +00:00
private void Awake() // 함수를 실행할거에요 -> 스크립트 시작 시 Awake를
2026-01-29 06:58:38 +00:00
{
2026-02-12 15:23:25 +00:00
if (health != null) // 조건이 맞으면 실행할거에요 -> 체력 스크립트가 있다면
2026-01-29 06:58:38 +00:00
{
2026-02-12 15:23:25 +00:00
health.OnHitEvent += () => anim.SetTrigger("Hit"); // 이벤트를 구독할거에요 -> 피격 시 Hit 트리거 발동을
health.OnDead += () => anim.SetBool("Die", true); // 이벤트를 구독할거에요 -> 사망 시 Die 상태 변경을
2026-01-29 06:58:38 +00:00
}
}
// ---------------------------------------------------------
// ⭐ [애니메이션 이벤트 전달자]
// 애니메이션 창에 적은 이름과 똑같은 함수를 만듭니다.
// ---------------------------------------------------------
2026-02-12 15:23:25 +00:00
public void StartWeaponCollision() // 함수를 선언할거에요 -> 무기 충돌 시작 이벤트 StartWeaponCollision을
2026-01-29 06:58:38 +00:00
{
2026-02-12 15:23:25 +00:00
if (attack != null) attack.StartWeaponCollision(); // 실행할거에요 -> 공격 스크립트의 충돌 시작 함수를
2026-01-29 06:58:38 +00:00
}
2026-02-12 15:23:25 +00:00
public void StopWeaponCollision() // 함수를 선언할거에요 -> 무기 충돌 종료 이벤트 StopWeaponCollision을
2026-01-29 06:58:38 +00:00
{
2026-02-12 15:23:25 +00:00
if (attack != null) attack.StopWeaponCollision(); // 실행할거에요 -> 공격 스크립트의 충돌 종료 함수를
2026-01-29 06:58:38 +00:00
}
// ---------------------------------------------------------
2026-02-12 15:23:25 +00:00
public void UpdateMove(float speedValue) => anim.SetFloat("Speed", speedValue); // 값을 전달할거에요 -> 애니메이터의 Speed 파라미터에
// public void TriggerAttack() => anim.SetTrigger("Attack");
public void TriggerThrow() => anim.SetTrigger("Throw"); // 신호를 보낼거에요 -> 애니메이터의 Throw 트리거에
2026-02-27 00:44:52 +00:00
// ─────────────────────────────────────────────────────────
// ⭐ 애니메이션 이벤트 전달자 — 활 관련 사운드
// FBX Throw 애니메이션 Events에 아래 함수 이름으로 등록해줘요
// ─────────────────────────────────────────────────────────
public void OnBowDraw() // 함수를 선언할거에요 -> 활 당기는 순간 소리 재생을 (애니메이션 이벤트)
{
if (attack != null) attack.PlayBowDrawSound(); // 실행할거에요 -> 활 당기는 소리를
}
2026-02-12 15:23:25 +00:00
public void SetCharging(bool isCharging) => anim.SetBool("isCharging", isCharging); // 값을 설정할거에요 -> 애니메이터의 isCharging 불리언에
2026-01-29 06:58:38 +00:00
}