Add sound effects and audio clips for weapons and actions; implement shot and damage sounds
This commit is contained in:
@@ -12,9 +12,10 @@ namespace Weapons
|
||||
|
||||
public override void Fire()
|
||||
{
|
||||
PlayShotSound();
|
||||
|
||||
var direction = (Target - (Vector2)firePoint.position).normalized;
|
||||
firePoint.up = direction;
|
||||
Debug.DrawLine(firePoint.position, Target, Color.red, 2f);
|
||||
|
||||
var projectile = Instantiate(projectilePrefab, firePoint.position, firePoint.rotation);
|
||||
projectile.TryGetComponent<IDamageInflectorSetup>(out var inflector);
|
||||
|
@@ -12,6 +12,7 @@ namespace Weapons
|
||||
[SerializeField] private float speed = 10f;
|
||||
[SerializeField] private float lifeTime = 5f;
|
||||
[SerializeField] private WeaponStats stats;
|
||||
[SerializeField] private AudioClip explosionSound;
|
||||
|
||||
public float Damage { get; private set; }
|
||||
public GameObject Owner { get; private set; }
|
||||
@@ -54,6 +55,12 @@ namespace Weapons
|
||||
hitCollider.TryGetComponent<Health>(out var health);
|
||||
health?.TakeDamage(Damage, Owner);
|
||||
}
|
||||
|
||||
if (explosionSound)
|
||||
{
|
||||
AudioSource.PlayClipAtPoint(explosionSound, transform.position);
|
||||
}
|
||||
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
|
@@ -14,6 +14,13 @@ namespace Weapons
|
||||
{
|
||||
var finalRange = GetFinalRange();
|
||||
var hits = Physics2D.OverlapCircleAll(transform.position, finalRange, targetMask);
|
||||
var hitAnybody = hits.Length > 0;
|
||||
|
||||
if (hitAnybody)
|
||||
{
|
||||
PlayShotSound();
|
||||
}
|
||||
|
||||
foreach (var hit in hits)
|
||||
{
|
||||
hit.TryGetComponent<Health>(out var health);
|
||||
|
@@ -12,6 +12,7 @@ namespace Weapons
|
||||
private float timer;
|
||||
|
||||
[OdinSerialize, InlineProperty] public WeaponStats weaponStats = new();
|
||||
public AudioClip shotSound;
|
||||
public Character character;
|
||||
|
||||
private void Update()
|
||||
@@ -39,6 +40,12 @@ namespace Weapons
|
||||
{
|
||||
return weaponStats.range * character.attributes.AttackRange;
|
||||
}
|
||||
|
||||
protected void PlayShotSound()
|
||||
{
|
||||
if (!shotSound) return;
|
||||
AudioSource.PlayClipAtPoint(shotSound, transform.position);
|
||||
}
|
||||
|
||||
public abstract void Fire();
|
||||
}
|
||||
|
Reference in New Issue
Block a user