using UnityEngine; using TMPro; [RequireComponent(typeof(AudioSource))] public class PlaySoundEvent : MonoBehaviour { [SerializeField] private AudioClip soundClip; // Assign the sound clip in the inspector [SerializeField] private float volume = 1f; [SerializeField] private float delaySeconds = 0f; public TMP_Text interactionPrompt; void DestroyObj() { Destroy(gameObject); } void OnTriggerEnter(Collider other) { if (other.CompareTag("Player")) // Assuming the player has the tag "Player" { Invoke("PlaySound", delaySeconds); // Play the sound after the delay Invoke("DestroyObj", delaySeconds + 0.1f); // Destroy the object after the delay } } void PlaySound() { if (soundClip != null) { Debug.Log("Playing sound: " + soundClip.name); SoundFXManager.instance.PlaySound(soundClip, transform, volume); } } }