Projext/Assets/Scripts/Player/Effect/Player Effect.cs
2026-02-03 23:41:49 +09:00

41 lines
1.3 KiB
C#

using UnityEngine;
/// <summary>
/// 플레이어의 시각(VFX) 및 청각(SFX) 효과를 전담하는 스크립트
/// </summary>
public class PlayerEffects : MonoBehaviour
{
[Header("--- 시각 효과 (VFX) ---")]
[SerializeField] private GameObject[] slashEffects; // 콤보별 다른 이펙트 가능
[SerializeField] private Transform slashSpawnPoint;
[Header("--- 청각 효과 (SFX) ---")]
[SerializeField] private AudioClip[] swingSounds;
private AudioSource _audioSource;
private void Awake()
{
_audioSource = GetComponent<AudioSource>();
if (_audioSource == null) _audioSource = gameObject.AddComponent<AudioSource>();
}
/// <summary>
/// 애니메이션 이벤트에서 호출할 함수
/// </summary>
/// <param name="comboIndex">현재 공격 콤보 번호 (0~2)</param>
public void PlaySlashEffect(int comboIndex)
{
// 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);
}
}
}