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);
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/_Project/Scripts/Combat/EnemyDeathSound.cs.meta
Normal file
2
Assets/_Project/Scripts/Combat/EnemyDeathSound.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9df6fea9a86daafae998f8eecc44ee7d
|
||||
|
|
@ -17,12 +17,7 @@ namespace TD.Combat
|
|||
[RequireComponent(typeof(TowerCombat))]
|
||||
public class TeslaTowerFireSound : MonoBehaviour
|
||||
{
|
||||
[Tooltip("Sound played each time the coil discharges.")]
|
||||
[SerializeField] private AudioClip fireClip;
|
||||
|
||||
[Tooltip("Pitch is randomized within this range each shot to avoid a mechanical loop.")]
|
||||
[SerializeField] private float minPitch = 0.93f;
|
||||
[SerializeField] private float maxPitch = 1.07f;
|
||||
[SerializeField] private SoundConfig fireSound;
|
||||
|
||||
private TowerCombat combat;
|
||||
|
||||
|
|
@ -43,7 +38,7 @@ namespace TD.Combat
|
|||
|
||||
private void HandleAreaFired(Vector3[] positions)
|
||||
{
|
||||
AudioManager.Instance?.Play(fireClip, AudioCategory.TowerFire, Random.Range(minPitch, maxPitch));
|
||||
AudioManager.Instance?.Play(fireSound.clip, AudioCategory.TowerFire, fireSound.RandomPitch(), fireSound.volume);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
41
Assets/_Project/Scripts/Combat/TowerBuiltSound.cs
Normal file
41
Assets/_Project/Scripts/Combat/TowerBuiltSound.cs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
// Assets/_Project/Scripts/Combat/TowerBuiltSound.cs
|
||||
using TD.Audio;
|
||||
using TD.Gameplay;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TD.Combat
|
||||
{
|
||||
/// <summary>
|
||||
/// Local-only audio for tower construction completion. Subscribes to
|
||||
/// <see cref="TowerInstance.OnBuiltClient"/> and plays a sound on every peer
|
||||
/// when the tower finishes building.
|
||||
/// Attach to any tower prefab and assign its clip in the Inspector.
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(TowerInstance))]
|
||||
public class TowerBuiltSound : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private SoundConfig builtSound;
|
||||
|
||||
private TowerInstance towerInstance;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
towerInstance = GetComponent<TowerInstance>();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (towerInstance != null) towerInstance.OnBuiltClient += HandleBuilt;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (towerInstance != null) towerInstance.OnBuiltClient -= HandleBuilt;
|
||||
}
|
||||
|
||||
private void HandleBuilt()
|
||||
{
|
||||
AudioManager.Instance?.Play(builtSound.clip, AudioCategory.UI, builtSound.RandomPitch(), builtSound.volume);
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/_Project/Scripts/Combat/TowerBuiltSound.cs.meta
Normal file
2
Assets/_Project/Scripts/Combat/TowerBuiltSound.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ce512ec39eb6a8f079c7b258a4d0ced1
|
||||
Loading…
Add table
Add a link
Reference in a new issue