Pause button also stops health regeneration timer.

Hello, I have player with life regeneration over time but the problem is when i press pause it also stops the timer for regeneration. How would I exclude the timer countdown from pausing when pause button is pressed?

Thank You.

I assume you are setting Time.timeScale to zero.

Replace Time.deltaTime with Time.unscaledDeltaTime or Time.time with Time.unscaledTime in your regeneration script. Also make sure you are not using FixedUpdate.


void Update()
if (playerLives != maxHearts)
countdownTime = Mathf.Max(0.0f, countdownTime - Time.unscaledTime);//unscaledDeltaTime);//deltaTime);

        if (countdownTime < 0.75f)

        int time = Mathf.FloorToInt(countdownTime);

        TimeText.text = "0" + (time / 60) + ":" + ((time % 60) < 10 ? ("0" + (time % 60).ToString()) : (time % 60).ToString());

btw I dont know how to copy paste code here to have proper indentation… sorry.