Monster Approach and react audio
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
using UnityEngine;
|
||||
using AudioSourceEvents;
|
||||
using Core;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using Core;
|
||||
using UnityEditor.Experimental.GraphView;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Audio;
|
||||
|
||||
namespace Minigames.DivingForPictures
|
||||
{
|
||||
@@ -28,6 +31,15 @@ namespace Minigames.DivingForPictures
|
||||
public bool IsPlayerInDetectionRange => playerInDetectionRange;
|
||||
public bool IsPictureTaken => pictureAlreadyTaken;
|
||||
|
||||
public enum MonsterSounds
|
||||
{Hello, RareBeast, Pooping,Smile,Whatsup1, Whatsup2}
|
||||
private AudioSource _audioSource;
|
||||
public AudioResource[] monsterClips;
|
||||
private AudioSource playerAudioSource;
|
||||
public AudioResource monsterSpottedAudio;
|
||||
private IAudioEventSource _eventSource;
|
||||
private GameObject playerObject;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Logging.Debug("Monster created: " + gameObject.name);
|
||||
@@ -36,13 +48,28 @@ namespace Minigames.DivingForPictures
|
||||
detectionCollider = GetComponent<CircleCollider2D>();
|
||||
|
||||
mainCamera = UnityEngine.Camera.main;
|
||||
_audioSource = GetComponent<AudioSource>();
|
||||
|
||||
|
||||
playerObject = GameObject.FindGameObjectsWithTag("Player")[0];
|
||||
playerAudioSource = playerObject.GetComponent<AudioSource>();
|
||||
_eventSource = playerAudioSource.RequestEventHandlers();
|
||||
_eventSource.AudioStopped += playerAudioDone;
|
||||
|
||||
|
||||
// Start checking if monster is off-screen
|
||||
StartCoroutine(CheckIfOffScreen());
|
||||
}
|
||||
|
||||
private void playerAudioDone(object sender, EventArgs e)
|
||||
{
|
||||
_audioSource.Play();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
playerAudioSource.resource = monsterSpottedAudio;
|
||||
playerAudioSource.Play();
|
||||
pictureAlreadyTaken = false;
|
||||
photoSequenceInProgress = false;
|
||||
}
|
||||
@@ -50,6 +77,7 @@ namespace Minigames.DivingForPictures
|
||||
private void OnDestroy()
|
||||
{
|
||||
Logging.Debug("Monster destroyed: " + gameObject.name);
|
||||
_eventSource.AudioStopped -= playerAudioDone;
|
||||
}
|
||||
|
||||
private IEnumerator CheckIfOffScreen()
|
||||
@@ -179,6 +207,37 @@ namespace Minigames.DivingForPictures
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayAudio(MonsterSounds soundToPlay)
|
||||
{
|
||||
switch (soundToPlay)
|
||||
{
|
||||
case MonsterSounds.Hello:
|
||||
_audioSource.resource = monsterClips[0];
|
||||
|
||||
break;
|
||||
case MonsterSounds.RareBeast:
|
||||
_audioSource.resource = monsterClips[1];
|
||||
|
||||
break;
|
||||
case MonsterSounds.Pooping:
|
||||
|
||||
break;
|
||||
case MonsterSounds.Smile:
|
||||
_audioSource.resource = monsterClips[3];
|
||||
|
||||
break;
|
||||
case MonsterSounds.Whatsup1:
|
||||
_audioSource.resource = monsterClips[4];
|
||||
|
||||
break;
|
||||
case MonsterSounds.Whatsup2:
|
||||
_audioSource.resource = monsterClips[5];
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_EDITOR
|
||||
|
||||
Reference in New Issue
Block a user