Update HealthComponent.cs

This commit is contained in:
BOT Alex 2024-02-04 10:40:05 +01:00
parent 4dbe23fb69
commit ca80f88c55
1 changed files with 25 additions and 3 deletions

View File

@ -33,17 +33,17 @@ public class HealthComponent : MonoBehaviour, ISquezeDamageReceiver
void Awake() void Awake()
{ {
currentHealth = maxHealth; currentHealth = maxHealth;
OnHealthChange.AddListener((_, _) => showRedTint = 1); OnHealthChange.AddListener((_, _) => showRedTint = true);
StartCoroutine(RedTintLoop()); StartCoroutine(RedTintLoop());
} }
float showRedTint = 0; bool showRedTint = false;
private IEnumerator RedTintLoop() private IEnumerator RedTintLoop()
{ {
SpriteRenderer sr = GetComponentInChildren<SpriteRenderer>(); SpriteRenderer sr = GetComponentInChildren<SpriteRenderer>();
while (true) while (true)
{ {
if (showRedTint < 0.1f) if (!showRedTint)
{ {
yield return new WaitForSecondsRealtime(0.1f); yield return new WaitForSecondsRealtime(0.1f);
continue; continue;
@ -53,6 +53,28 @@ public class HealthComponent : MonoBehaviour, ISquezeDamageReceiver
yield return new WaitForSecondsRealtime(0.1f); yield return new WaitForSecondsRealtime(0.1f);
sr.color = Color.white; sr.color = Color.white;
yield return new WaitForSecondsRealtime(0.1f); yield return new WaitForSecondsRealtime(0.1f);
sr.color = Color.red;
yield return new WaitForSecondsRealtime(0.1f);
sr.color = Color.white;
yield return new WaitForSecondsRealtime(0.1f);
sr.color = Color.red;
yield return new WaitForSecondsRealtime(0.1f);
sr.color = Color.white;
yield return new WaitForSecondsRealtime(0.1f);
sr.color = Color.red;
yield return new WaitForSecondsRealtime(0.1f);
sr.color = Color.white;
yield return new WaitForSecondsRealtime(0.1f);
sr.color = Color.red;
yield return new WaitForSecondsRealtime(0.1f);
sr.color = Color.white;
yield return new WaitForSecondsRealtime(0.1f);
sr.color = Color.red;
yield return new WaitForSecondsRealtime(0.1f);
sr.color = Color.white;
yield return new WaitForSecondsRealtime(0.1f);
showRedTint = false;
} }
} }