Unity 最简单的携程

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class IEnumeratorTest : MonoBehaviour {
 
    public float delayedSeconds = 2.3f;
 
    private void Start()
    {
        Material mat = GetComponent().material;
        StartCoroutine(Fade(mat));
        StartCoroutine(DelayedDestroy());
    }
 
    IEnumerator DelayedDestroy()
    {
        Debug.Log(string.Format("GameObject will be destroyed in {0} seconds.", delayedSeconds));
        yield return new WaitForSeconds(delayedSeconds);
        Destroy(this.gameObject);
    }
 
    IEnumerator Fade(Material mat)
    {
        Color col = mat.color;
        while (col.a > 0f)
        {
            col.a -= 0.01f;
            mat.color = col;
            yield return null;
        }
    }
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。