The way I see the AddStamina() function, it’s a stamina regeneration function. But you’re saying you want a delay before it starts regenerating. So something doesn’t add up here.
My first idea of how to do it would be:
GetWorldTimerManager().SetTimer(TimerHandle, this, &AMain::StartStaminaRegeneration, time, false);
void AMain::StartStaminaRegeneration()
{
bStaminaRegenerates = true;
}
AMain::Tick(float DeltaTime)
{
if (bStaminaRegenerates)
{
Stamina += StaminaDrainRate * DeltaTime;
if (Stamina >= MaxStamina)
{
Stamina = MaxStamina;
bStaminaRegenerates = false;
}
}
}
And you set bStaminaRegenerates to false when you start sprinting again. You can use a second looping timer instead of Tick() if you like.