Time
| Type | Class (static members) |
|---|---|
| Namespace | UnityEngine |
Time
The Time class tells you how much time has passed: since the last frame, since the game started, and at what speed the game is running. It's the key to making things move at the same speed on every computer.
Frames are like the steps you take while walking. A fast computer takes many small steps per second; a slow one takes fewer, bigger steps. Time.deltaTime is the length of your last step in seconds. Multiply your speed by it and you cover the same distance per second no matter how many steps you take.
Static Properties
| Name | Type | Description |
|---|---|---|
deltaTime | float | Seconds since the last frame (e.g. 0.016 at 60 FPS). Multiply movement by this. Inside FixedUpdate it returns fixedDeltaTime. |
fixedDeltaTime | float | Seconds between physics steps. Default 0.02 (50 per second). |
time | float | Seconds since the game started (scaled by timeScale). Good for cooldowns. |
timeScale | float | Game speed. 1 = normal, 0.5 = slow motion, 0 = paused. |
unscaledDeltaTime | float | Like deltaTime but ignores timeScale. Use for pause menus and UI. |
unscaledTime | float | Like time but ignores timeScale. |
realtimeSinceStartup | float | Real seconds since the app launched. Keeps counting even when paused. |
frameCount | int | How many frames have been started. |
Code Samples
Frame-rate independent movement
// BAD: moves 0.1 units per frame. 60 FPS = 6 units/s, 144 FPS = 14.4 units/s.
transform.position += Vector3.forward * 0.1f;
// GOOD: moves 5 units per second on every machine.
transform.position += Vector3.forward * 5f * Time.deltaTime;
A cooldown timer
using UnityEngine;
public class Dash : MonoBehaviour
{
[SerializeField] private float cooldown = 2f;
private float readyAt;
void Update()
{
if (Input.GetKeyDown(KeyCode.LeftShift) && Time.time >= readyAt)
{
Debug.Log("Dash!");
readyAt = Time.time + cooldown;
}
}
}
Pause and slow motion
public void Pause() { Time.timeScale = 0f; }
public void Resume() { Time.timeScale = 1f; }
public void SlowMotion() { Time.timeScale = 0.3f; }
UI that still animates while paused
void Update()
{
// Spins even when Time.timeScale is 0.
loadingIcon.Rotate(0f, 0f, -180f * Time.unscaledDeltaTime);
}
What happens at runtime
When you set timeScale = 0:
Time.deltaTimebecomes 0, so anything multiplied by it stops moving.Time.timestops increasing, so cooldowns freeze.FixedUpdatestops being called, so physics freezes.- Animators (in Normal update mode) freeze.
WaitForSecondsnever finishes. Updatestill runs every frame. Input still works, which is how you can un-pause.
Common Mistakes
- Forgetting deltaTime in
Updatemovement, or using it where you shouldn't:rb.linearVelocity = dir * speedis already "per second", so don't multiply velocity by deltaTime. - Thinking timeScale 0 stops everything. Your own
Updatecode that doesn't use deltaTime keeps running. - Forgetting to reset timeScale when loading a new scene from a pause menu. It stays at 0 and the new scene is frozen.
- Slow motion looks choppy? Physics still steps every 0.02 game seconds, so it steps less often in real time. Also scale
Time.fixedDeltaTimeby the same factor, or enable Interpolate on Rigidbodies.
See also
This page is a simplified, AI-assisted interpretation. For the complete and authoritative reference, see the official Unity documentation.