using UnityEngine;
using System.Collections;
public class InvokeTest : MonoBehaviour {
// Use this for initialization
void Start () {
//Invoke ("TestInvoke",2f);//2秒之后只调用一次TestInvoke函数
print ("2f hou diao yong test hanshu");
InvokeRepeating ("TestInvokeRepeating",2f,1f);//5f秒之后每隔1f秒重复调用TestInvokeRepeating函数
}
// Update is called once per frame
void Update () {
}
public void TestInvokeRepeating(){
print ("InvokeRepeating");
}
public void TestInvoke(){
print ("Invoke");
}
void OnDisable(){//当脚本enable=false时调用此函数
CancelInvoke ();//结合使脚本enable=false来停止InvokeRepeating重复调用此函数
}
}
using System.Collections;
public class InvokeTest : MonoBehaviour {
// Use this for initialization
void Start () {
//Invoke ("TestInvoke",2f);//2秒之后只调用一次TestInvoke函数
print ("2f hou diao yong test hanshu");
InvokeRepeating ("TestInvokeRepeating",2f,1f);//5f秒之后每隔1f秒重复调用TestInvokeRepeating函数
}
// Update is called once per frame
void Update () {
}
public void TestInvokeRepeating(){
print ("InvokeRepeating");
}
public void TestInvoke(){
print ("Invoke");
}
void OnDisable(){//当脚本enable=false时调用此函数
CancelInvoke ();//结合使脚本enable=false来停止InvokeRepeating重复调用此函数
}
}