In this lesson, you will learn how to manipulate the global Time.timeScale property to create professional slow-motion effects without breaking your movement logic.
Understanding TimeScale
In Unity, Time.timeScale acts as a global multiplier for the passage of time within your game. By default, it is set to 1.0. If you change it to 0.5, time effectively moves at half speed. If you set it to 0, time stands still—which is the standard way to pause a game.
The magic of Time.timeScale is how it interacts with the Time.deltaTime value you learned about previously. When you multiply your movement speed by Time.deltaTime, you are already asking Unity, "How much time passed since the last frame?" When you change Time.timeScale, Unity automatically scales the value of Time.deltaTime to match.
This means that if you wrote your movement scripts correctly using Time.deltaTime, you don't need to rewrite anything to support slow motion!
Implementing the Effect
Imagine you want to trigger a slow-motion effect when a player holds a button. You can adjust the scale directly from your script:
void Update()
{
if (Input.GetKey(KeyCode.LeftShift))
{
// Set time to run at 20% speed
Time.timeScale = 0.2f;
}
else
{
// Return to normal speed
Time.timeScale = 1.0f;
}
}
Important Considerations
Because Time.timeScale affects the entire engine, it will slow down everything—including your character movement, physics simulations, and animations. However, some UI elements or timers that rely on "real-time" (outside the game's simulated clock) will keep running at normal speed.
If you find that your audio or specific UI transitions feel "wrong" during slow motion, keep in mind that Time.timeScale is a global setting. Always ensure your gameplay logic strictly uses Time.deltaTime so that your objects don't move at full speed while the rest of the world is frozen.
Key Takeaway: By using Time.deltaTime in your movement logic, Unity automatically synchronizes your objects with the global Time.timeScale, allowing you to create smooth slow-motion or pause effects with a single line of code.