Newer
Older
Dreamsturbia-Project-IADE-Unity3D / Assets / Scripts / Sound / SfxPlayer.cs
@Rackday Rackday on 21 Aug 655 bytes Project Added
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));
        }
    }
}