unity 渐变消失_Unity使用协程简单实现渐变特效

协程:

可以理解是一种特殊的方法,我们可以控制该方法的执行时间(开始,结束,延迟执行)

//实例:实现数字累加特效

public class IEnutor : MonoBehaviour

{

public Text text;

public int min, max;

private int count;

// Start is called before the first frame update

void Start()

{

StartCoroutine(Fade());

}

IEnumerator Fade()

{

text.text = min.ToString();

count = min;

for (int i = 0; i < max - min; i++)

{

count++;

yield return new WaitForSeconds(1);//等待(等待1秒钟),再执行后面代码

text.text = count.ToString();

}

//text.text = max.ToString();

//StopCoroutine(Fade());//停止协程

//StopAllCoroutines();//停止当前脚本所有协程

//yield return new WaitForEndOfFrame();

//等待所有相机和GUI被渲染完成后执行后面代码

//yield return new WaitForFixedUpdate();//等待FixedUpdate方法执行完,再执行

//WaitForSeconds和WaitForSecondsRealtime的本质区别

//Time.timeScale = 0.5f;

//print(Time.time);

//yield return new WaitForSeconds(5);//依旧等待5秒

//print(Time.time);

//yield return new WaitForSecondsRealtime(5);//等待2.5秒

//print(Time.time);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值