All checks were successful
Build project / Build for (StandaloneLinux64, 6000.0.37f1) (push) Successful in 5m53s
Build project / Build for (StandaloneWindows64, 6000.0.37f1) (push) Successful in 5m30s
Build project / Publish to itch.io (StandaloneLinux64) (push) Successful in 4s
Build project / Publish to itch.io (StandaloneWindows64) (push) Successful in 4s
34 lines
972 B
C#
34 lines
972 B
C#
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);
|
|
}
|
|
}
|
|
}
|