From ec464e48e1c68737a820f70e5d40a87818ce2175 Mon Sep 17 00:00:00 2001
From: miepzerino <o.skotnik@gmail.com>
Date: Fri, 15 Dec 2023 23:45:56 +0000
Subject: [PATCH] Added pickups

---
 Assets/Scripts/Damageable.cs |   24 ++++++++++++++++++++----
 1 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/Assets/Scripts/Damageable.cs b/Assets/Scripts/Damageable.cs
index 2b2fcf6..b738468 100644
--- a/Assets/Scripts/Damageable.cs
+++ b/Assets/Scripts/Damageable.cs
@@ -1,3 +1,4 @@
+using System;
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
@@ -32,8 +33,6 @@
         {
             if (value > MaxHealth)
             {
-
-                Debug.Log("Warum?");
                 _health = MaxHealth;
             }
             else
@@ -85,10 +84,27 @@
     {
         if (IsAlive && !isInvincible)
         {
-            Health -= damage;
+            int actualDamageAmount = Mathf.Min(damage, Health);
+            Health -= actualDamageAmount;
             isInvincible = true;
 
-            CharacterEvents.characterDamaged.Invoke(gameObject, damage);
+            CharacterEvents.characterDamaged.Invoke(gameObject, actualDamageAmount);
         }
     }
+
+    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;
+
+        }
+        return result;
+    }
 }

--
Gitblit v1.9.3