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 float currentHealth;
public HealthBar healthBar; public HealthBar healthBar;
private bool attack; 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; private bool canWalk = true;
@ -40,6 +46,8 @@ public class Player : MonoBehaviour
var em = dmgParticleSystem.emission; var em = dmgParticleSystem.emission;
em.enabled = true; em.enabled = true;
StartCoroutine(Timer()); StartCoroutine(Timer());
timerRegen = 0.0f;
startRegen = false;
if (currentHealth <= 0) if (currentHealth <= 0)
{ {
Panel.SetActive(true); Panel.SetActive(true);
@ -106,6 +114,26 @@ public class Player : MonoBehaviour
myAnimator.SetFloat("lastMoveX", inputHorizontal); myAnimator.SetFloat("lastMoveX", inputHorizontal);
myAnimator.SetFloat("lastMoveY", inputVertical); 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(); HandleInput();