miepzerino
2023-12-16 1d74f3204692bb69aabf3c57fbdf4601a31a311f
Assets/Scripts/Damageable.cs
@@ -5,9 +5,11 @@
public class Damageable : MonoBehaviour
{
#if (UNITY_EDITOR)
    // ONLY FOR DEBUG USE
    [SerializeField]
    private bool selfDamage = false;
#endif
    Animator animator;
    [SerializeField]
@@ -20,6 +22,10 @@
    private bool isInvincible = false;
    private float timeSinceHit = 0f;
    public float invincibilityTime = 0.25f;
    public AudioClip hitSound;
    public AudioClip healSound;
    public AudioClip deathSound;
    public int MaxHealth
    {
@@ -42,6 +48,10 @@
            if (value <= 0)
            {
                IsAlive = false;
                if (deathSound != null)
                {
                    SoundManager.instance.PlaySoundAtPoint(gameObject, deathSound.name);
                }
            }
        }
    }
@@ -74,10 +84,12 @@
                timeSinceHit += Time.deltaTime;
            }
        }
#if (UNITY_EDITOR)
        if (selfDamage)
        {
            Hit(10);
        }
#endif
    }
    public void Hit(int damage)
@@ -89,6 +101,10 @@
            isInvincible = true;
            CharacterEvents.characterDamaged.Invoke(gameObject, actualDamageAmount);
            if (hitSound != null)
            {
                SoundManager.instance.PlaySoundAtPoint(gameObject, hitSound.name);
            }
        }
    }
@@ -103,6 +119,10 @@
            CharacterEvents.characterHealed.Invoke(gameObject, actualHealAmount);
            result = true;
            if (healSound != null)
            {
                SoundManager.instance.PlaySoundAtPoint(gameObject, healSound.name);
            }
        }
        return result;