Unity 实现间隔一定时间执行一个事件

实现效果

对于一些流程性功能,这个使用起来很方便

在这里插入图片描述

完整代码

只需20行,当物体激活的时候执行一次:

using System.Collections;
using UnityEngine;
using UnityEngine.Events;
public class Step : MonoBehavIoUr
{
    void Start()
    {
        StartCoroutine(CE());
    }
    public float[] t = new float[3];
    public UnityEvent[] e = new UnityEvent[3];
    public IEnumerator CE()
    {
        for (int i = 0; i < t.Length; i++)
        {
            yield return new WaitForSeconds(t[i]);
            e[i].Invoke();
        }
    }
}

相关文章

实现Unity AssetBundle资源加载管理器 AssetBundle是实现资源...
Unity3D 使用LineRenderer绘制尾迹与虚线 1.添加LineRendere...
Unity 添加新建Lua脚本选项 最近学习Unity的XLua热更新框架的...
挂载脚本时文件名和类名的关联方式 写过Unity脚本的人应该都...
Unity单例基类的实现方式 游戏开发的过程中我们经常会将各种...
这篇文章主要介绍了Unity游戏开发中外观模式是什么意思,具有...