death sounds, build sounds, better audio management
This commit is contained in:
parent
a7b2d1854d
commit
9f25844657
26 changed files with 313 additions and 12 deletions
42
Assets/_Project/Scripts/Combat/EnemyDeathSound.cs
Normal file
42
Assets/_Project/Scripts/Combat/EnemyDeathSound.cs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
// Assets/_Project/Scripts/Combat/EnemyDeathSound.cs
|
||||
using TD.Audio;
|
||||
using TD.Gameplay;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TD.Combat
|
||||
{
|
||||
/// <summary>
|
||||
/// Local-only audio for enemy death. Subscribes to <see cref="EnemyHealth.OnDiedClient"/>
|
||||
/// and plays a randomly chosen clip from <see cref="deathClips"/>.
|
||||
/// Attach to any enemy prefab and assign its clips in the Inspector.
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(EnemyHealth))]
|
||||
public class EnemyDeathSound : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private SoundConfig[] deathSounds;
|
||||
|
||||
private EnemyHealth enemyHealth;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
enemyHealth = GetComponent<EnemyHealth>();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (enemyHealth != null) enemyHealth.OnDiedClient += HandleDied;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (enemyHealth != null) enemyHealth.OnDiedClient -= HandleDied;
|
||||
}
|
||||
|
||||
private void HandleDied()
|
||||
{
|
||||
if (deathSounds == null || deathSounds.Length == 0) return;
|
||||
var sound = deathSounds[Random.Range(0, deathSounds.Length)];
|
||||
AudioManager.Instance?.Play(sound.clip, AudioCategory.EnemyHitDeath, sound.RandomPitch(), sound.volume);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue