unity延时方法Invoke和InvokeRepeating
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 测试unity延时方法Invoke和InvokeRepeating
/// </summary>
public class Test1 : MonoBehaviour
{
private float timer = 0;
// Use this for initialization
void Start()
{
timer = 0;
//从现在起1秒后执行
Invoke("Btn1", 1.0f);
//从现在开始2秒后执行,并且每隔1秒执行一次
InvokeRepeating("Btn2", 2.0f, 1.0f);
}
void Btn1()
{
Debug.Log("方法一执行了");
}
void Btn2()
{
Debug.Log("方法二执行了");
}
// Update is called once per frame
void Update()
{
timer += Time.deltaTime;
Debug.Log("时间是" + timer);
}
}
结果如下: