Version: 2020.1
public static float time ;

描述

该帧开始的时间(只读)。此为自游戏启动以来的时间(以秒为单位)。

Time.time 是应用程序已运行的时间(以秒为单位)。它是只读的。

应用程序在每帧开始时接收当前的 Time.time,该值按帧递增。每个帧的 time 调用将接收相同的值。在从 FixedUpdate 中调用时,将返回 Time.fixedTime 属性。

应避免常规的(每帧)调用:Time.time 倾向于提供应用程序已经运行的时间长度,而不是每帧的时间。

The value of Time.time is undefined during Awake messages and will start after all messages are finished. Time.time will not update if the Editor is paused. See Time.realtimeSinceStartup 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 float nextFire = 0.0f;

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