using UnityEngine; [RequireComponent(typeof(AudioSource))] public sealed class OneShotCueProbe : MonoBehaviour { [SerializeField] private AudioClip cue; [SerializeField, Range(0f, 1f)] private float volumeScale = 0.7f; private AudioSource source; private void Awake() { source = GetComponent(); source.playOnAwake = false; source.loop = false; } [ContextMenu("Play Cue (Play Mode)")] public void PlayCue() { if (!Application.isPlaying || !isActiveAndEnabled) return; if (cue == null || source == null || !source.isActiveAndEnabled) { Debug.LogError("Assign a cue and enable this dedicated AudioSource.", this); return; } source.PlayOneShot(cue, Mathf.Clamp01(volumeScale)); } private void OnDisable() { if (source != null) source.Stop(); } }