Question by
marlavdm · Sep 23, 2018 at 07:35 PM ·
timepausetime.deltatimepause game
How to pause my game when using Time.DeltaTime?
I have a fish character that has a health slider, while the fish is swimming, his health slowly decreases using the following code:
void Update()
{
HealthSlider.healthSlider.value -= Time.deltaTime;
}
But I can't pause my game using: Time.timeScale = 0; anymore. The game doesn't pause when I press the pause button. I need my fish's health slider to slowly decrease, but I also need to be able to pause my game. Any suggestions?
I also tried the following, but this didn't work either.
HealthSlider.healthSlider.value -= Time.unscaledDeltaTime;
Comment
deltatime is frame time (not real world time). Using Time.time ins$$anonymous$$d
I don't face this problem with the following simple script:
public Slider s ;
public void Pause()
{
Time.timeScale = 0 ;
}
public void Resume()
{
Time.timeScale = 1 ;
}
protected void Update()
{
s.value -= Time.deltaTime ;
}
The value of the slider stops decreasing when Pause
is called (using a button). When the Resume
function is called, the value decreases.