- Home /
 
Time unscaledDeltaTime not working?
So in my game over screen, theres a reward bar that fills as the player scores, for now the bar is static, so if the max score to fill the bar is 20 and the player has a score of 10, half the bar will be filled once the player dies.
The "gift" bar in this case is a slider, I wanted to make the slider to fill as time goes by while the player is in the game over menu as shown, so I made this bit of code:
 public void PlayerDied() {
             gameOver = true;
             if (gameOver == true) {
                 highScore2.text = highScore.text; //Game Over HiScore
                 gameOverText.SetActive(true);
                 Time.timeScale = 0f;
     
                 rewardBar.value = 0;
                 rewardBar.value = SaveManager.Instance.state.allScore * Time.unscaledDeltaTime;
          }
       }
 
               The problem is within the last line, since the timeScale = 0 I think should use the unscaledDeltaTime to "animate" the reward bar, but when using it, the bar doesnt fill at all, the slider stays at the minimum value. Am I wrongly using unscaledDeltaTime? Thanks in advance.
Time.unscaledDeltaTime is a really a small number by itself. It's sth. like 0.035 in average. So result highly depends on the greatness of your Save$$anonymous$$anager.Instance.state.allScore value because you multiply it by unscaledDeltaTime. And i guess your PlayerDied() method is called once when player died. So even you add it ins$$anonymous$$d of multiplying, it wont make any difference at all. 
If you want to animate progress of your slider until it reaches the Save$$anonymous$$anager.Instance.state.allScore (im not sure but i guess this is what you are trying!!!) do it in Update as well.
 void Update(){
      if (Time.timeScale == 0){
           if(rewardBar.value < Save$$anonymous$$anager.Instance.state.allScore)
                rewardBar.value += Time.unscaledDeltaTime;
           else 
                rewardBar.value = Save$$anonymous$$anager.Instance.state.allScore;
      }
 }
 
                 Are you sure what DeltaTIme is? It is the time between each full frame of code. $$anonymous$$eaning that if your player scores 20 and you you do 20  Time.unscaledDeltaTime and you have say... 50 FPS, then your deltaTime is 20ms, so you are scaling 20  0.02f. $$anonymous$$eaning your total value is .4f. And will change depending on frame rate. What exactly are you trying to achieve with this? If you want your bar to actually fill up, you would say rewardBar.value += Save$$anonymous$$anager.Instance.state.allScore * Time.unscaledDeltaTime; However, this would just fill the bar over the course of 1 second, not giving you the actual score amount. 
Your answer
 
             Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Find out if gameObject is UI in 4.6 1 Answer
Options UI over all scenes 1 Answer