美文网首页
Unity 最简单的携程

Unity 最简单的携程

作者: psmyfish | 来源:发表于2020-09-07 15:11 被阅读0次
    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;
            }
        }
    }
    

    相关文章

      网友评论

          本文标题:Unity 最简单的携程

          本文链接:https://www.haomeiwen.com/subject/flflektx.html