You are executing the HungerController() function on everyframe. That resets everything in the function.
Basically move everything in update() except the float declarations. Put those in Start().
If you need to call HungerController() on its own from someplace else, then just move
float CurrentTime = 0;
float NeededTime = 10;
in Start() and CurrentTime += Time.deltaTime; in Update();
But i don’t see why not put them in update and have them in their own function.
Easy answer, update is called every frame, that means HungerController is also called every frame and the values are reseted every time it is called.
Put the declarations outside HungerController. Like this:
float CurrentTime = 0;
float NeededTime = 10; // If you make it public you can tweak it in the inspector
void Update () {
if (MouseVisible)
Screen.showCursor = true;
else
Screen.showCursor = false;
// List of functions
HungerController ();
}
void HungerController ()
{
CurrentTime += Time.deltaTime;
if (CurrentTime > NeededTime)
{
CurrentTime = 0;
Hunger--;
}
}