Add sound effects and audio clips for weapons and actions; implement shot and damage sounds
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Collections;
|
||||
using Data;
|
||||
using Sirenix.Serialization;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
@@ -16,6 +17,8 @@ namespace Systems
|
||||
[OdinSerialize, SerializeField] private int coins = 0;
|
||||
[OdinSerialize, SerializeField] private float roundTime = 60f;
|
||||
[OdinSerialize, SerializeField] private int maxRounds = 20;
|
||||
[OdinSerialize, SerializeField] private Scene winScene;
|
||||
[OdinSerialize, SerializeField] private Transform arenaCenter;
|
||||
|
||||
[OdinSerialize, SerializeField] private Character player;
|
||||
|
||||
@@ -35,14 +38,9 @@ namespace Systems
|
||||
private void Awake()
|
||||
{
|
||||
if (Instance == null)
|
||||
{
|
||||
Instance = this;
|
||||
// DontDestroyOnLoad(gameObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
private void Start()
|
||||
@@ -57,6 +55,7 @@ namespace Systems
|
||||
|
||||
for (currentRound = 1; currentRound <= maxRounds; currentRound++)
|
||||
{
|
||||
player.transform.position = new Vector3(arenaCenter.position.x, arenaCenter.position.y, player.transform.position.z);
|
||||
OnRoundStart?.Invoke(currentRound);
|
||||
timer = roundTime;
|
||||
|
||||
@@ -71,6 +70,8 @@ namespace Systems
|
||||
OnStoreOpen?.Invoke();
|
||||
yield return new WaitUntil(() => StoreIsClosed);
|
||||
}
|
||||
|
||||
SceneManager.LoadScene(winScene.name);
|
||||
}
|
||||
|
||||
public void AddCoins(int amount)
|
||||
|
@@ -11,6 +11,7 @@ namespace Systems
|
||||
|
||||
[Self, SerializeField] private Character character;
|
||||
[SerializeField] private float initialHealth = 100f;
|
||||
[SerializeField] private AudioClip damageSound;
|
||||
|
||||
public GameObject LastAttacker => lastAttacker;
|
||||
|
||||
@@ -24,8 +25,15 @@ namespace Systems
|
||||
public void TakeDamage(float damage, GameObject attacker = null)
|
||||
{
|
||||
lastAttacker = attacker;
|
||||
|
||||
var effectiveDamage = Math.Max(damage - character.attributes.Armor, 1);
|
||||
character.attributes.ModifyHealth(-effectiveDamage);
|
||||
|
||||
if (damageSound)
|
||||
{
|
||||
AudioSource.PlayClipAtPoint(damageSound, transform.position);
|
||||
}
|
||||
|
||||
OnTakeDamage?.Invoke();
|
||||
}
|
||||
}
|
||||
|
@@ -20,6 +20,7 @@ namespace UI
|
||||
[SerializeField] private int weaponsCount = 2;
|
||||
[SerializeField, Scene] private ShopManager shopManager;
|
||||
[SerializeField, Scene] private UpgradeManager upgradeManager;
|
||||
[SerializeField] private AudioClip levelUpSound;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
@@ -34,6 +35,11 @@ namespace UI
|
||||
|
||||
private void OnLevelUp()
|
||||
{
|
||||
if (levelUpSound)
|
||||
{
|
||||
AudioSource.PlayClipAtPoint(levelUpSound, new Vector3(0f, 0f, 0f));
|
||||
}
|
||||
|
||||
Show();
|
||||
}
|
||||
|
||||
|
@@ -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