1.Public Functions
1).CancelInvoke : 取消此MonoBehaviour上的所有Invoke调用。
public void CancelInvoke();
using UnityEngine;
using System.Collections.Generic;
public class ExampleScript : MonoBehaviour
{
public GameObject projectile;
void Start()
{
// 从2秒开始,每0.3秒重复该方法
InvokeRepeating("LaunchProjectile", 2, 0.3F);
}
void LaunchProjectile()
{
// Create a projectile GameObject and set its velocity to a random direction
GameObject instance = Instantiate(projectile);
Rigidbody rigidbody = instance.GetComponent<Rigidbody>();
rigidbody.velocity = Random.insideUnitSphere * 5;
}
void Update()
{
// 取消所有Invoke调用
if (Input.GetButton("Fire1"))
CancelInvoke();
}
}