63 lines
1.6 KiB
C#
63 lines
1.6 KiB
C#
using AudioSourceEvents;
|
|
using System;
|
|
using System.Diagnostics.Tracing;
|
|
using UnityEngine;
|
|
using UnityEngine.Audio;
|
|
|
|
public class GardenerAudioController : MonoBehaviour
|
|
{
|
|
|
|
public AudioSource gardenerAudioPlayer;
|
|
public AudioSource mowerAudioPlayer;
|
|
public AudioResource mowerStartAudio;
|
|
public AudioResource mowerLoopAudio;
|
|
public AudioResource gardenerFleeAudioClip;
|
|
public AudioResource gardenerChaseAudioClip;
|
|
|
|
public SpriteRenderer gardenerSprite;
|
|
|
|
private IAudioEventSource _eventSource;
|
|
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
void Start()
|
|
{
|
|
}
|
|
|
|
void GardenerIsOnScreen()
|
|
{
|
|
Debug.Log("Gardener spotted!");
|
|
}
|
|
|
|
public void StartMowerSound()
|
|
{
|
|
mowerAudioPlayer.Play();
|
|
_eventSource = mowerAudioPlayer.RequestEventHandlers();
|
|
_eventSource.AudioStopped += PlayMowerLoop;
|
|
|
|
}
|
|
|
|
private void PlayMowerLoop(object sender, EventArgs e)
|
|
{
|
|
_eventSource.AudioStopped -= PlayMowerLoop;
|
|
mowerAudioPlayer.resource = mowerLoopAudio;
|
|
mowerAudioPlayer.loop = true;
|
|
mowerAudioPlayer.Play();
|
|
}
|
|
|
|
public void PlayGardenerVOClip(bool fleeing)
|
|
{
|
|
if (gardenerAudioPlayer.isPlaying) { return; }
|
|
if (fleeing) {
|
|
gardenerAudioPlayer.resource = gardenerFleeAudioClip;
|
|
gardenerAudioPlayer.Play();
|
|
}
|
|
if (!fleeing)
|
|
{
|
|
gardenerAudioPlayer.resource = gardenerChaseAudioClip;
|
|
gardenerAudioPlayer.Play();
|
|
|
|
}
|
|
|
|
}
|
|
}
|