using System.Collections; using System.Collections.Generic; using UnityEngine; public class SfxPlayer : MonoBehaviour { public AudioClip audioCip; private AudioSource audioSource; // Start is called before the first frame update void Start() { audioSource = GetComponent<AudioSource>(); audioSource.clip = audioCip; } public void Play(double delayTime) { audioSource.PlayScheduled(AudioSettings.dspTime + delayTime); } // Update is called once per frame void Update() { if (!audioSource.isPlaying) { Play(Random.Range(1, 30)); } } }