Spatial lawnmower audio implemented
This commit is contained in:
62
Assets/Scripts/Sound/GardenerAudioController.cs
Normal file
62
Assets/Scripts/Sound/GardenerAudioController.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
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();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Sound/GardenerAudioController.cs.meta
Normal file
2
Assets/Scripts/Sound/GardenerAudioController.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f0f1834ce0c7b0b42b633a6d2bd67698
|
||||
21
Assets/Scripts/Sound/GardenerVisibilityDetection.cs
Normal file
21
Assets/Scripts/Sound/GardenerVisibilityDetection.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
public class GardenerVisibilityDetection : MonoBehaviour
|
||||
{
|
||||
public GardenerAudioController gardenerAudioController;
|
||||
private Animator _animator;
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
_animator = GetComponent<Animator>();
|
||||
}
|
||||
|
||||
private void OnBecameVisible()
|
||||
{
|
||||
gardenerAudioController.PlayGardenerVOClip(_animator.GetBool("IsScared?"));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
2
Assets/Scripts/Sound/GardenerVisibilityDetection.cs.meta
Normal file
2
Assets/Scripts/Sound/GardenerVisibilityDetection.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 52a39ff5639315a499266196941d6894
|
||||
Reference in New Issue
Block a user