Hi there, I’m trying to make a game where when you are near a FireCamp, you gain HP, and else, you lose HP (like a survival game).
My code was working just fine (like a week ago), and I modified a couple of stuffs, not really in link with the HP, and the moment I put a UI with a HP Bar, I’ve realised that the moment I happen to be near a FireCamp, I’m losing HP and winning HP at the same time, and when I go out of the healing zone, I still win HP (which was not the case 1 week ago). I’ve deleted everything and wrote back everything and I still have the problem. I can’t find a proper way to debug it either. Here is my code :
void Update () {
if (isInZone)
{
_startWinningLife = true;
_startLosingLife = false;
}
else if (!isInZone)
{
_startLosingLife = true;
_startWinningLife = false;
}
LifeManagement();
}
// Manages all the states of Life Alterations
void LifeManagement()
{
if (_startWinningLife)
{
if (!_isWinningLife)
{
WinLife();
}
_startWinningLife = false;
}
if (_startLosingLife)
{
if (!_isLosingLife)
{
LoseLife();
}
_startLosingLife = false;
}
// Starts the losing hp cycle and stops the winning hp cycle
void LoseLife()
{
_isWinningLife = false;
StopCoroutine(LifeWinning());
_isLosingLife = true;
StartCoroutine(LifeLosing());
}
// Player loses Hp every Seconds
IEnumerator LifeLosing()
{
yield return new WaitForSeconds(1);
_hp = _hp - _overtimeDamage;
yield return StartCoroutine(LifeLosing());
}
// Player wins Hp every Seconds
IEnumerator LifeWinning()
{
yield return new WaitForSeconds(1);
_hp = _hp + _overtimeHeal;
yield return StartCoroutine(LifeWinning());
}
Can someone please help me?
Thanks a lot