Delay Call function for Unity3d

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.