Hey,
Here is the issue, i have some states on the player’s hunger. Depending on his current state, diferente things will happen, for exemple if he is hungry, he moves 50% slower. Here is the code for that
CurrentNourishment ReverseNourishment()
{
if(CurHunger < 5)
{
currentNourishment = CurrentNourishment.Nourished;
}
if(CurHunger <= 50 && CurHunger > 5)
{
currentNourishment = CurrentNourishment.Fine;
}
if(CurHunger <= 75 && CurHunger > 50)
{
currentNourishment = CurrentNourishment.Hungry;
}
if(CurHunger > 75)
{
currentNourishment = CurrentNourishment.Starving;
}
return currentNourishment;
}
I thought about using a While, but it kept crashing, i thought about a switch, but that repeated the whole thing several times, so if i put curSpeed–; it would keep happening until he couldn’t even move, when in reality, i only want that to happen once. I understand why this happens, but i dont know how to fix it. Here is my update.
void Update()
{
if(!isDead)
{
IncreaseHunger();
IncreaseThirst();
ReverseNourishment();
}
}
I understand that it runs several times on update until the condition is not met, but how can i fix this?