Unity Delay method Invoke and Invokerepeating

Source: Internet
Author: User

There are two built-in delay methods inside the monobehaviour

Invoke

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

Invokerepeating

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

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

Here is the code note:

Using unityengine;using System.collections;public class Delayscript:monobehaviour {    //Current time    private float Nowtime;    The number of times the repeating method was executed    private int count;    Use the this for initialization    void Start () {        nowtime = time.time;        Debug.Log ("Time point:" +nowtime);        This. Invoke ("SetTimeOut", 3.0f);        This. Invokerepeating ("SetInterval", 2.0f, 1.0f);    }    private void SetTimeOut ()    {        nowtime = time.time;        Debug.Log ("Execution delay method:" + nowtime);    }    private void SetInterval ()    {        nowtime = time.time;        Debug.Log ("Execute repeating Method:" + nowtime);        Count + = 1;        if (count==5) this            . Cancelinvoke ();    }}

Unity Delay method Invoke and Invokerepeating

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.