From 68ec3ed7918bbe97fe6c8a2197b7c7ecf91cab8a Mon Sep 17 00:00:00 2001 From: Jakub Sztuba Date: Mon, 13 Jun 2022 17:38:09 +0200 Subject: [PATCH] Added health recovering feature --- Assets/Scripts/Player.cs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Assets/Scripts/Player.cs b/Assets/Scripts/Player.cs index 7a8dc0de..b3543b1b 100644 --- a/Assets/Scripts/Player.cs +++ b/Assets/Scripts/Player.cs @@ -19,7 +19,13 @@ public class Player : MonoBehaviour public float currentHealth; public HealthBar healthBar; private bool attack; + + private float timerRegen = 0f; + private float timerTick = 0f; + private float waitRegen = 8.0f; + private float waitTick = 1.0f; + private bool startRegen = false; private bool canWalk = true; @@ -40,6 +46,8 @@ public class Player : MonoBehaviour var em = dmgParticleSystem.emission; em.enabled = true; StartCoroutine(Timer()); + timerRegen = 0.0f; + startRegen = false; if (currentHealth <= 0) { Panel.SetActive(true); @@ -106,6 +114,26 @@ public class Player : MonoBehaviour myAnimator.SetFloat("lastMoveX", inputHorizontal); myAnimator.SetFloat("lastMoveY", inputVertical); } + + timerRegen += Time.deltaTime; + if(timerRegen >= waitRegen) + { + startRegen = true; + } + + if (startRegen == true) + { + timerTick += Time.deltaTime; + if(timerTick >= waitTick) + { + if(currentHealth < 10) + { + currentHealth = currentHealth + 1; + healthBar.SetHealth(currentHealth); + timerTick = 0f; + } + } + } //} HandleInput();