Unity delay method Invoke and InvokeRepeating

 

There are two built-in delay methods in MonoBehaviour

Invoke

1
2
3
Invoke(methodName:  string , time:  float ):  void ;
methodName:方法名
time:多少秒后执行

InvokeRepeating

1
2
3
4
InvokeRepeating(methodName:  string , time:  float , repeatRate:  float ):  void ;
methodName:方法名
time:多少秒后执行
repeatRate:重复执行间隔

There are also two important methods:

  • IsInvoking: used to determine whether a method is delayed and is about to be executed
  • CancelInvoke: Cancel all delay methods on the script (note that gameObject.SetActive(false) does not work, which is the difference from Coroutine) 

There are two built-in delay methods in MonoBehaviour

Invoke

1
2
3
Invoke(methodName:  string , time:  float ):  void ;
methodName:方法名
time:多少秒后执行

InvokeRepeating

1
2
3
4
InvokeRepeating(methodName:  string , time:  float , repeatRate:  float ):  void ;
methodName:方法名
time:多少秒后执行
repeatRate:重复执行间隔

There are also two important methods:

  • IsInvoking: used to determine whether a method is delayed and is about to be executed
  • CancelInvoke: Cancel all delay methods on the script (note that gameObject.SetActive(false) does not work, which is the difference from Coroutine) 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324946960&siteId=291194637