Version: 2019.3
LanguageEnglish
  • C#

Time.time

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public static float time;

Description

The time at the beginning of this frame (Read Only). This is the time in seconds since the start of the game.

Time.time is the amount of time in seconds that the application has been running for. It is read-only.

The application receives the current Time.time at the beginning of each frame, with the value increasing per frame. A time call per frame receives the same value. When called from FixedUpdate it returns the Time.fixedTime property.

Regular (per frame) calls should be avoided: Time.time is intended to supply the length of time the application has been running for, and not the time per frame.

The value of Time.time is undefined during Awake messages and will start after all messages are finished.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Example : MonoBehaviour { private int width, height; private Rect rect; private GUIStyle labelStyle; private string currentTime;

void Awake() { width = Screen.width; height = Screen.height; rect = new Rect(10, 10, width - 20, height - 20); }

void OnGUI() { // Display the label at the center of the window. labelStyle = new GUIStyle(GUI.skin.GetStyle("label")); labelStyle.alignment = TextAnchor.MiddleCenter;

// Modify the size of the font based on the window. labelStyle.fontSize = 12 * (width / 200);

// Obtain the current time. currentTime = Time.time.ToString("f6"); currentTime = "Time is: " + currentTime + " sec.";

// Display the current time. GUI.Label(rect, currentTime, labelStyle); } }