xtpro
xtpro

Reputation: 75

How to make visual timer go x times slower and how to stop it?

So I am making a game with visual timer that shows current playtime of the player as "MM:SS". Now I've managed to do this just fine, but I haven't yet been to make the time go slower or to stop it when I want to. I am using TimeSpan to show the time in a very similar way as shown in one of this question's answers.

public TimeSpan RunningTime{ get { return DateTime.UtcNow - _started; } }
private DateTime _started;

public void Start()
{
_started = DateTime.UtcNow;
}

and then I read the RunningTime in other script and show it for the player in the GUI. When player presses for example key "a", the game goes into slow motion mode where time and player moves 0.5 times as fast as normally. But I can't get the effect to work in the GUI time text.

Upvotes: 0

Views: 369

Answers (1)

giacomelli
giacomelli

Reputation: 7417

Just use Time.timeScale to stop or slow down the time inside your game:

Time.timeScale = 1; // The default value.
Time.timeScale = 0; // Stop the time.
Time.timeScale = 0.5f; // Slower time.
Time.timeScale = 2f; // Faster time.

Then use Time.timeSinceLevelLoad to show the current playtime to the player.

Upvotes: 1

Related Questions