Unity Delay method Invoke and Invokerepeating
There are two built-in delay methods inside the
monobehaviour
string float float void ; MethodName: Method name time: How many seconds to execute repeatrate: repeat Interval
string float void ; MethodName: Method name time: How many seconds to execute
There are two important ways to do this:
- Isinvoking: Used to determine if a method is delayed and is about to be executed
- Cancelinvoke: Cancels all delay methods on the script
usingUnityengine;usingSystem.Collections; Public classDelayscript:monobehaviour {//Current Time Private floatNowtime; //number of times the repeating method was executed Private intcount; //Use this for initialization voidStart () {nowtime=Time.time; Debug.Log ("point in time:"+nowtime); This. Invoke ("SetTimeOut",3.0f); This. Invokerepeating ("setinterval",2.0f,1.0f); } Private voidSetTimeOut () {nowtime=Time.time; Debug.Log ("execution Delay Method:"+nowtime); } Private voidsetinterval () {nowtime=Time.time; Debug.Log ("To perform a repeating method:"+nowtime); Count+=1; if(count==5) This. Cancelinvoke (); }}
Unity Delay method Invoke and Invokerepeating