What I need is to increment player stats every few second and be able to interrupt this process with any key pressed down.
Below is my coroutine. It's running endlessly, any advice?
IEnumerator PlayerAction(PlayerStats playerStats, int incrementor1)
{
bool loop = true;
while (loop)
{
if (Input.anyKeyDown)
{
loop = false;
Debug.Log("Action is break");
yield break;
}
else
{
yield return new WaitForSeconds(2);
playerStats.Energy += incrementor1;
GameClock.Tic++;
Debug.Log("My first courutine is working!");
}
}
}