The player runs into colliders which causes the game to freeze. However the health bar is supposed to be constantly decreasing. So when the player hits the colliders that pauses the game, the health bar is also frozen. Is there a way to freeze everything besides the health bar?
I assume your health bar is time based. The reason it stops is because Time.deltaTime is 0 and therefore you are not subtracting anything from your calculations. One solution is to make a copy of the deltaTime for one frame and assign it to a variable in Start(). You can then use it when timeScale is 0 Something like;
if (Time.timeScale > 0.01)
health -= Time.deltaTime * rate;
health -= myDeltaTime * rate;
myDeltaTime is assigned Time.deltaTime in Start(). Since this code only samples a single frame, the calculations using it may be a bit slow or fast, but generally it is close.
Wrap Time in a singleton class (maybe called GameTime) where you can control different time scales – maybe one for gameplay, one for your HUD (e.g., health bar), and one for the GUI. For example, you could call GameTime.gameplayDeltaTime for your player, but GameTime.hudDeltaTime for your health bar updates.
Or just base your health bar on Time.realtimeSinceStartup instead of deltaTime. But the singleton wrapper is a much more flexible and robust solution.