Time.time 时间

static var time : float

Description描述

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

此帧开始的时间(只读)。这是以秒计算到游戏开始的时间。也就是说,从游戏开始到到现在所用的时间。

When called from inside MonoBehaviour's FixedUpdate, returns fixedTime property.

当在MonoBehaviourFixedUpdate里调用的时候,返回的是fixedTime属性。

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;
			duck clone = Instantiate(projectile, transform.position, transform.rotation);
		}
	}
}
// Instantiates a projectile off every 0.5 seconds,
// if the Fire1 button (default is ctrl) is pressed.
//如果Fire1按钮被按下(默认为ctrl),每0.5秒实例化一发子弹
var projectile : GameObject;
var fireRate = 0.5;
private var nextFire = 0.0;

function Update () {
	if (Input.GetButton ("Fire1") && Time.time > nextFire) {
		nextFire = Time.time + fireRate;
		var clone = Instantiate (projectile, transform.position, transform.rotation);
	}
}
最后修改:2011年1月16日 Sunday 17:51

本脚本参考基于Unity 3.4.1f5

英文部分版权属©Unity公司所有,中文部分© Unity圣典 版权所有,未经许可,严禁转载 。