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;
}
}
}
网友评论