Added health recovering feature

This commit is contained in:
Jakub Sztuba 2022-06-13 17:38:09 +02:00
parent f1adc298bb
commit 68ec3ed791

View File

@ -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();