From d95020b910bc69ab733f87d5d0238fe2d1164590 Mon Sep 17 00:00:00 2001
From: miepzerino <o.skotnik@gmail.com>
Date: Sat, 16 Dec 2023 18:52:45 +0000
Subject: [PATCH] Overhauled audio management
---
Assets/Scripts/Damageable.cs | 38 +++++++++++++++++++++++++++++++++++++-
1 files changed, 37 insertions(+), 1 deletions(-)
diff --git a/Assets/Scripts/Damageable.cs b/Assets/Scripts/Damageable.cs
index d5ae844..6fd7016 100644
--- a/Assets/Scripts/Damageable.cs
+++ b/Assets/Scripts/Damageable.cs
@@ -1,12 +1,16 @@
+using Assets.Scripts.Enums;
+using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Damageable : MonoBehaviour
{
+#if (UNITY_EDITOR)
// ONLY FOR DEBUG USE
[SerializeField]
private bool selfDamage = false;
+#endif
Animator animator;
[SerializeField]
@@ -20,6 +24,10 @@
private float timeSinceHit = 0f;
public float invincibilityTime = 0.25f;
+ public SoundName hitSound;
+ public SoundName healSound;
+ public SoundName deathSound;
+
public int MaxHealth
{
get { return _maxHealth; }
@@ -41,6 +49,11 @@
if (value <= 0)
{
IsAlive = false;
+ // Not needed here as it's played from the Animator
+ //if (deathSound != null)
+ //{
+ SoundManager.instance.PlaySoundAtPoint(gameObject, deathSound);
+ //}
}
}
}
@@ -73,18 +86,41 @@
timeSinceHit += Time.deltaTime;
}
}
+#if (UNITY_EDITOR)
if (selfDamage)
{
Hit(10);
}
+#endif
}
public void Hit(int damage)
{
if (IsAlive && !isInvincible)
{
- Health -= damage;
+ int actualDamageAmount = Mathf.Min(damage, Health);
+ Health -= actualDamageAmount;
isInvincible = true;
+
+ CharacterEvents.characterDamaged.Invoke(gameObject, actualDamageAmount);
+ SoundManager.instance.PlaySoundAtPoint(gameObject, hitSound);
}
}
+
+ public bool Heal(int healAmount)
+ {
+ bool result = false;
+ if (IsAlive && Health < MaxHealth)
+ {
+ int actualHealAmount = Mathf.Min(healAmount, MaxHealth - Health);
+ Health += actualHealAmount;
+
+ CharacterEvents.characterHealed.Invoke(gameObject, actualHealAmount);
+
+ result = true;
+ SoundManager.instance.PlaySoundAtPoint(gameObject, healSound);
+
+ }
+ return result;
+ }
}
--
Gitblit v1.10.0