1.Invoke (string methodname,float time)
- Call the MethodName function at a certain time
Using unityengine;using System.Collections; public class Example:monobehaviour {public rigidbody projectile; void Launchprojectile () { Rigidbody instance =instantiate (projectile); Instance.velocity = random.insideunitsphere* 5; } public void Awake () { Invoke ("Launchprojectile", 2);} }
2.InvokeRepeating (String methodname,float time,float repeatrate)
- Call the MethodName function every once in a while
Call the MethodName method in time seconds; The method that specifies the method name according to the timing
It is called once every repeatrate time from the first call.
Using unityengine;using System.Collections; public class Example:monobehaviour {public rigidbody projectile; void Launchprojectile () { Rigidbody instance =instantiate (projectile); Instance.velocity = random.insideunitsphere* 5; } public void Awake () { invokerepeating ("Launchprojectile", 2, 0.3F); After 2 seconds, call every 0.3f }}
3.CanceInvoke ("MethodName")
- Cancels all calls that are named MethodName.
From:http://blog.sina.com.cn/s/blog_682e58590102uyfk.html
Delay Call function for Unity3d