Spatial lawnmower audio implemented
This commit is contained in:
@@ -11,10 +11,14 @@ public class GardenerChaseBehavior : MonoBehaviour
|
||||
[SerializeField] private Animator animator;
|
||||
[SerializeField] public GameObject lawnMowerRef;
|
||||
private TweenBase tweenRef;
|
||||
public GardenerAudioController audioController;
|
||||
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
tweenRef = Tween.Spline (ChaseSpline, GardenerObject, 0, 1, false, chaseDuration, chaseDelay, Tween.EaseLinear, Tween.LoopType.None, HandleTweenStarted, HandleTweenFinished);
|
||||
|
||||
}
|
||||
|
||||
void HandleTweenFinished ()
|
||||
|
||||
@@ -21,6 +21,7 @@ public class LawnMowerChaseBehaviour : MonoBehaviour
|
||||
public GameObject gardenerRef = null;
|
||||
public Animator gardenerAnimator = null;
|
||||
public bool gardenerChasing = true;
|
||||
public GardenerAudioController gardenerAudioController;
|
||||
|
||||
void Start()
|
||||
{
|
||||
@@ -28,6 +29,7 @@ public class LawnMowerChaseBehaviour : MonoBehaviour
|
||||
|
||||
float distanceToStart = Mathf.Abs(startPercentage - 0f);
|
||||
float distanceToEnd = Mathf.Abs(startPercentage - 1f);
|
||||
gardenerAudioController.StartMowerSound();
|
||||
|
||||
if (distanceToStart < distanceToEnd)
|
||||
{
|
||||
|
||||
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