Invoke()
用法(usage):public void Invoke(string methodName,float time);
参数(Parameter):
- methodName:string 类型的方法名。
- time:执行方法的时间。
Official Explaining:Invokes the method methodName in time seconds.
官方解释:调用方法“methodName”在一定时间之后。
实例:
using UnityEngine;
using System.Collections.Generic;
public class InvokeInit:MonoBehaviour
{
void Start(){
//在2秒后调用方法“InvokedMethod”
Invoke("InvokedMethod",2f);
}
void InvokedMethod(){
Debug.Log("Invoke");
}
}
InvokeRepeating()
用法(usage):public void InvokeRepeating(string methodName,float time,float repeatRate)
参数(Parameter):
methodName:string类型的方法名。
time:执行方法的时间。
repeatRate:从第一次调用开始,每隔repeatRate时间调用一次。
实例:
using UnityEngine;
using System.Collections.Generic;
public class InvokeInit:MonoBehaviour
{
void Start(){
//在2秒后调用方法“InvokedMethod”,每3秒重复一次调用
InvokeRepeating("InvokedMethod",2f,3);
}
void InvokedMethod(){
Debug.Log("InvokeRepeating");
}
}