Files
AppleHillsProduction/Assets/Scripts/Sound/BushAudioController.cs
2025-10-29 17:01:02 +01:00

57 lines
1.4 KiB
C#

using AudioSourceEvents;
using Input;
using System;
using System.Diagnostics.Tracing;
using UnityEngine;
using UnityEngine.Audio;
public class BushAudioController : MonoBehaviour
{
private IAudioEventSource _eventSource;
public AudioSource VOPlayer;
public AudioSource SFXPlayer;
public AudioResource reactionClipToPlay;
public AudioResource flashSFXClipToPlay;
public BirdGameStats birdGameStats;
public AudioResource[] birdCounterClip;
private int _birdCounter;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
_eventSource = VOPlayer.RequestEventHandlers();
_eventSource.AudioStopped += PlayBirdCounter;
}
public void PlayPhotoSoundBite()
{
VOPlayer.resource = reactionClipToPlay;
VOPlayer.Play();
}
public void PlayFlashSound()
{
SFXPlayer.resource = flashSFXClipToPlay;
SFXPlayer.Play();
}
private void PlayBirdCounter(object sender, EventArgs e)
{
_eventSource.AudioStopped -= PlayBirdCounter;
VOPlayer.resource = birdCounterClip[birdGameStats.birdsFoundInLevel];
VOPlayer.Play();
birdGameStats.BirdFound();
}
public void OnDisable()
{
// Unsubscribe from events when disabled
_eventSource.AudioStopped -= PlayBirdCounter;
}
}