Newer
Older
Dreamsturbia-Project-IADE-Unity3D / Assets / Scripts / Sound / SfxPlayer.cs
@Rackday Rackday on 21 Aug 655 bytes Project Added
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class SfxPlayer : MonoBehaviour
  5. {
  6. public AudioClip audioCip;
  7. private AudioSource audioSource;
  8. // Start is called before the first frame update
  9. void Start()
  10. {
  11. audioSource = GetComponent<AudioSource>();
  12. audioSource.clip = audioCip;
  13. }
  14. public void Play(double delayTime)
  15. {
  16. audioSource.PlayScheduled(AudioSettings.dspTime + delayTime);
  17. }
  18. // Update is called once per frame
  19. void Update()
  20. {
  21. if (!audioSource.isPlaying)
  22. {
  23. Play(Random.Range(1, 30));
  24. }
  25. }
  26. }