| 1 | using System.Collections; |
| 2 | using System.Collections.Generic; |
| 3 | using UnityEngine; |
| 4 | |
| 5 | public class SFXInstance : MonoBehaviour |
| 6 | { |
| 7 | private AudioSource src; |
| 8 | private float timer = 0; |
| 9 | private bool started = false; |
| 10 | |
| 11 | [SerializeField] private AudioClip click, connect, disconnect; |
| 12 | |
| 13 | public void PlayAudio(SFXSpawner.Sounds sound) |
| 14 | { |
| 15 | src = GetComponent<AudioSource>(); |
| 16 | |
| 17 | switch(sound) |
| 18 | { |
| 19 | case SFXSpawner.Sounds.Click: |
| 20 | src.PlayOneShot(click); |
| 21 | timer = click.length * 2; |
| 22 | break; |
| 23 | |
| 24 | case SFXSpawner.Sounds.Connect: |
| 25 | src.PlayOneShot(connect); |
| 26 | timer = connect.length * 2; |
| 27 | break; |
| 28 | |
| 29 | case SFXSpawner.Sounds.Disconnect: |
| 30 | src.PlayOneShot(disconnect); |
| 31 | timer = disconnect.length * 2; |
| 32 | break; |
| 33 | } |
| 34 | |
| 35 | started = true; |
| 36 | } |
| 37 | |
| 38 | void Update() |
| 39 | { |
| 40 | if(started) |
| 41 | { |
| 42 | timer -= Time.deltaTime; |
| 43 | |
| 44 | if (timer <= 0) |
| 45 | Destroy(gameObject); |
| 46 | } |
| 47 | } |
| 48 | } |