From 0981d20371e2c95af1685e5634e940412d3806bd Mon Sep 17 00:00:00 2001
From: billc27 <110593711+billc27@users.noreply.github.com>
Date: Fri, 10 May 2024 14:43:50 +0700
Subject: [PATCH] style: add green effect when restoring health

---
 Assets/Scenes/Main.unity              |  2 +-
 Assets/Scripts/Player/PlayerHealth.cs | 16 ++++++++++++++--
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/Assets/Scenes/Main.unity b/Assets/Scenes/Main.unity
index fd86356..d55b109 100644
--- a/Assets/Scenes/Main.unity
+++ b/Assets/Scenes/Main.unity
@@ -1634,7 +1634,7 @@ MonoBehaviour:
   m_Name: 
   m_EditorClassIdentifier: 
   m_Material: {fileID: 0}
-  m_Color: {r: 1, g: 0, b: 0, a: 0}
+  m_Color: {r: 1, g: 1, b: 1, a: 0}
   m_RaycastTarget: 1
   m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
   m_Maskable: 1
diff --git a/Assets/Scripts/Player/PlayerHealth.cs b/Assets/Scripts/Player/PlayerHealth.cs
index 2838f95..d3c3650 100644
--- a/Assets/Scripts/Player/PlayerHealth.cs
+++ b/Assets/Scripts/Player/PlayerHealth.cs
@@ -13,7 +13,8 @@ namespace Nightmare
         public Image damageImage;
         public AudioClip deathClip;
         public float flashSpeed = 5f;
-        public Color flashColour = new Color(1f, 0f, 0f, 0.1f);
+        public Color redColour = new Color(1f, 0f, 0f, 0.1f);
+        public Color greenColour = new Color(0f, 1f, 0f, 0.1f);
 
         Animator anim;
         AudioSource playerAudio;
@@ -21,6 +22,7 @@ namespace Nightmare
         PlayerShooting playerShooting;
         bool isDead;
         bool damaged;
+        int damageAmount = 0;
 
         // Cheat No Damage
         public bool isCheatNoDamage = false;
@@ -54,7 +56,14 @@ namespace Nightmare
             if (damaged)
             {
                 // ... set the colour of the damageImage to the flash colour.
-                damageImage.color = flashColour;
+                if (damageAmount > 0) // Take Damage
+                {
+                    damageImage.color = redColour;
+                }
+                else if (damageAmount < 0) // Restore Health
+                {
+                    damageImage.color = greenColour;
+                }
             }
             // Otherwise...
             else
@@ -76,6 +85,9 @@ namespace Nightmare
             // Set the damaged flag so the screen will flash.
             damaged = true;
 
+            // Set damage amount to get the right color effect
+            damageAmount = amount;
+
             // Reduce the current health by the damage amount.
             currentHealth -= amount;
 
-- 
GitLab