| | | 1 | | using UnityEngine; |
| | | 2 | | |
| | | 3 | | public class FireBasedAudioManager : MonoBehaviour, IFireDependant |
| | | 4 | | { |
| | | 5 | | // Audio source to be played |
| | | 6 | | public AudioSource audioSource; |
| | | 7 | | // How many fires must be lit to play the audio |
| | | 8 | | public int fireLimit; |
| | | 9 | | // Time between the audio source is played |
| | | 10 | | public float timeInterval; |
| | | 11 | | // Indicates whether we are above the fire limit so the audio must be played |
| | | 12 | | private bool shouldPlay; |
| | | 13 | | // Last time audio was played |
| | 8 | 14 | | private float lastPlayed = 0f; |
| | | 15 | | |
| | | 16 | | // Start is called before the first frame update |
| | | 17 | | void Awake() |
| | 4 | 18 | | { |
| | 4 | 19 | | this.audioSource = this.GetComponent<AudioSource>(); |
| | 4 | 20 | | this.shouldPlay = true; |
| | 4 | 21 | | } |
| | | 22 | | |
| | | 23 | | // Update is called once per frame |
| | | 24 | | void Update() |
| | 88500 | 25 | | { |
| | 177000 | 26 | | if (this.shouldPlay) { |
| | 88500 | 27 | | if (this.lastPlayed >= this.timeInterval) |
| | 220 | 28 | | { |
| | 220 | 29 | | this.audioSource.Play(); |
| | 220 | 30 | | this.lastPlayed = 0f; |
| | 220 | 31 | | } |
| | 88500 | 32 | | this.lastPlayed += Time.deltaTime; |
| | 88500 | 33 | | } |
| | 88500 | 34 | | } |
| | | 35 | | |
| | | 36 | | public void NotifyFireChange(int fireCount) |
| | 16 | 37 | | { |
| | 16 | 38 | | this.shouldPlay = fireCount >= fireLimit; |
| | 16 | 39 | | } |
| | | 40 | | } |