Version: 2021.2
LanguageEnglish
  • C#

Time.timeAsDouble

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 double timeAsDouble;

Description

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

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

Double precision version of time. This offers more precision than a float or single value, particularly over extended periods of real-world time. In almost all cases, you should use the timeAsDouble equivalent over time.

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

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

The value of Time.timeAsDouble is undefined during Awake messages and starts after all messages are finished. Time.timeAsDouble does not update if the Editor is paused. See Time.realtimeSinceStartupAsDouble for a time value that is unaffected by pausing.

//If the Fire1 button is pressed, a projectile
//will be Instantiated every 0.5 seconds.

using UnityEngine; using System.Collections;

public class Example : MonoBehaviour { public GameObject projectile; public float fireRate = 0.5f; private double nextFire = 0.0f;

void Update() { if (Input.GetButton("Fire1") && Time.timeAsDouble > nextFire) { nextFire = Time.timeAsDouble + fireRate; Instantiate(projectile, transform.position, transform.rotation); } } }