- Home /
Countdown timer using Time.unscaledDeltaTime not working as expected.
As you can see in the image, The number is printing but the value is never decreasing only staying at 4.986... Simply, I am trying to make a countdown I've looked through many other unity answer posts and answers all showing the same/similar format to what I'm doing, I feel I'm simply missing something but can someone help my issue, Thanks (-:
private void Update()
{
if (Input.GetMouseButtonDown(0) && startText.gameObject.active)
{
startText.gameObject.SetActive(false);
startTimer = true;
}
float countTime = 5f;
float timeTarget = 0f;
countTime -= Time.unscaledDeltaTime;
if (countTime > timeTarget && startTimer)
{
Debug.Log(Time.unscaledDeltaTime);
counterText.gameObject.SetActive(true);
counterText.text = countTime.ToString("f1");
}
else if (countTime <= 0f)
{
Time.timeScale = 1.0f;
PlayerMove.canJump = true;
ObjectMove.gameActive = true;
}
}
Oh and, The time.timescale is set to "0.0f" in the start void as I don't want anything to start moving until the user wants them to hence why I'm using time.unscaledDeltaTime :-3
Answer by matthewosb003 · Jan 06, 2020 at 05:03 PM
After realising how to have a functioning brain, and taking about 2 hours to realise this is an update function I removed the two floats as, well Obviously they were being set to default value every frame... Well done me for being a bit dumb.
Your answer
Follow this Question
Related Questions
Pause & Unpause Different timers 1 Answer
Timer and gui text 2 Answers
How would I make a timer frame independent? 1 Answer
Is it possible to turn a script On/Off ? (Solved) 3 Answers
how to reset deltatime back to 1f when scene has reloaded?, 1 Answer