public void Invoke (string methodName, float time);

描述

time 秒后调用 methodName 方法。

如果时间设置为 0,则在下一个更新周期调用方法。在这种情况下,直接调用函数会更好。

为获得更好的性能和可维护性,请改为使用协程

using UnityEngine;
using System.Collections.Generic;

public class ExampleScript : MonoBehaviour { // Launches a projectile in 2 seconds

Rigidbody projectile;

void Start() { Invoke("LaunchProjectile", 2.0f); }

void LaunchProjectile() { Rigidbody instance = Instantiate(projectile); instance.velocity = Random.insideUnitSphere * 5.0f; } }