26 lines
596 B
C#
26 lines
596 B
C#
using UnityEngine;
|
|
|
|
[RequireComponent(typeof(AudioSource))]
|
|
public class PlaySoundEvent : MonoBehaviour
|
|
{
|
|
[SerializeField] private AudioClip soundClip; // Assign the sound clip in the inspector
|
|
|
|
|
|
void OnTriggerEnter(Collider other)
|
|
{
|
|
if (other.CompareTag("Player")) // Assuming the player has the tag "Player"
|
|
{
|
|
PlaySound();
|
|
Destroy(gameObject); // Remove the trigger
|
|
}
|
|
}
|
|
|
|
void PlaySound()
|
|
{
|
|
if (soundClip != null)
|
|
{
|
|
SoundFXManager.instance.PlaySound(soundClip, transform, 1f);
|
|
}
|
|
}
|
|
}
|