Projext/Assets/Scripts/Player/Effect/Player Effect.cs
2026-02-13 00:23:25 +09:00

41 lines
2.2 KiB
C#

using UnityEngine; // 유니티 엔진의 기본 기능을 불러올거에요 -> UnityEngine을
/// <summary>
/// 플레이어의 시각(VFX) 및 청각(SFX) 효과를 전담하는 스크립트
/// </summary>
public class PlayerEffects : MonoBehaviour // 클래스를 선언할거에요 -> MonoBehaviour를 상속받는 PlayerEffects를
{
[Header("--- 시각 효과 (VFX) ---")] // 인스펙터 창에 제목을 표시할거에요 -> --- 시각 효과 (VFX) --- 를
[SerializeField] private GameObject[] slashEffects; // 배열을 선언할거에요 -> 베기 이펙트 프리팹들을
[SerializeField] private Transform slashSpawnPoint; // 변수를 선언할거에요 -> 이펙트 생성 위치를
[Header("--- 청각 효과 (SFX) ---")] // 인스펙터 창에 제목을 표시할거에요 -> --- 청각 효과 (SFX) --- 를
[SerializeField] private AudioClip[] swingSounds; // 배열을 선언할거에요 -> 휘두르는 소리 클립들을
private AudioSource _audioSource; // 변수를 선언할거에요 -> 오디오 소스 컴포넌트를
private void Awake() // 함수를 실행할거에요 -> 스크립트 시작 시 Awake를
{
_audioSource = GetComponent<AudioSource>(); // 컴포넌트를 가져올거에요 -> 오디오 소스를
if (_audioSource == null) _audioSource = gameObject.AddComponent<AudioSource>(); // 없으면 추가할거에요 -> 오디오 소스 컴포넌트를
}
/// <summary>
/// 애니메이션 이벤트에서 호출할 함수
/// </summary>
/// <param name="comboIndex">현재 공격 콤보 번호 (0~2)</param>
public void PlaySlashEffect(int comboIndex) // 함수를 선언할거에요 -> 베기 이펙트를 재생하는 PlaySlashEffect를
{
// 1. 사운드 재생
if (swingSounds.Length > comboIndex && swingSounds[comboIndex] != null) // 조건이 맞으면 실행할거에요 -> 해당 인덱스의 소리가 있다면
{
_audioSource.PlayOneShot(swingSounds[comboIndex]); // 재생할거에요 -> 해당 오디오 클립을
}
// 2. 이펙트 생성
if (slashEffects.Length > comboIndex && slashEffects[comboIndex] != null && slashSpawnPoint != null) // 조건이 맞으면 실행할거에요 -> 해당 인덱스의 이펙트와 생성 위치가 있다면
{
GameObject slash = Instantiate(slashEffects[comboIndex], slashSpawnPoint.position, slashSpawnPoint.rotation); // 생성할거에요 -> 이펙트 오브젝트를 생성 위치에
Destroy(slash, 1.0f); // 파괴할거에요 -> 생성된 이펙트를 1초 뒤에
}
}
}