0

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.

Community
  • 1
  • 1
xtpro
  • 75
  • 5

1 Answers1

1

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.

giacomelli
  • 7,287
  • 2
  • 27
  • 31
  • This worked out perfectly until I encountered another problem: When my character dies he goes ragdoll. At this point I want the ragdoll to move realistically and also timer to stop counting until player respawns. How could this be implemented? Same problem occurs when player finishes the stage, goes ragdoll and the time should stop. Now in both situations time keeps going as I can't make timeScale go zero as then the ragdoll effect wouldn't work out. – xtpro Dec 02 '14 at 10:07