团结实现物体延时出现的方法

  介绍

小编给大家分享一下团结实现物体延时出现的方法,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获、下面让我们一起去了解一下吧!

新建一个多维数据集和飞机,隐藏立方体,脚本挂在飞机上。

<强> 1。更新计时器实现

using  System.Collections;   using  System.Collections.Generic;   using  UnityEngine;   ,//一个隐藏的物体等待t秒后显示,updata计时器实现   时间:public  class  activeShow  MonoBehaviour  {   ,   立方体,public  GameObject ;   ,public  int  t;   ,private  float  m_timer=0;   ,   ,//Use 却;能够for 初始化   ,void  Start  (), {   ,   ,}   ,   ,//Update  is  nbsp; once  per 框架   ,void  Update  (), {   ,m_timer +=Time.deltaTime;   ,如果(m_timer> 5) {   cube.SetActive才能(真正的);   m_timer才能=0;   ,}   ,}   }

<强> 2。调用实现

using  System.Collections;   using  System.Collections.Generic;   using  UnityEngine;   ,   一个隐藏的物体等待t秒后显示,调用实现   时间:public  class  ShowT  MonoBehaviour  {   ,   立方体,public  GameObject ;   ,public  int  t;//等待时间   ,   ,//Use 却;能够for 初始化   ,void  Start  (), {   ,调用(“ActiveShow",, t);   ,}   ,   ,//Update  is  nbsp; once  per 框架   ,void  Update  (), {   ,   ,}   ,   ,public  void  ActiveShow () {   ,cube.SetActive(真正的);   ,}   }

<强> 3。invokeRepeating实现强(这个是用来凑数的)

void  Start  (), {   ,InvokeRepeating (“ActiveShow",, t, 1000);   以前,}

<强> 4。协程实现

using  System.Collections;   using  System.Collections.Generic;   using  UnityEngine;   ,//一个隐藏的物体等待t秒后显示,协程实现   时间:public  class  HideInSeconds  MonoBehaviour  {   ,   立方体,public  GameObject ;   ,IEnumerator 即;   ,   ,//Use 却;能够for 初始化   ,void  Start  (), {   ,ie=waitFourSeconds ();   ,StartCoroutine (ie);   ,   ,}   ,   ,//Update  is  nbsp; once  per 框架   ,void  Update  (), {   ,   ,}   ,   ,IEnumerator  waitFourSeconds () {   ,油品收率return  new  WaitForSeconds(4.0度);   ,cube.SetActive(真正的);   ,}   }

以上是“团结实现物体延时出现的方法”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注行业资讯频道!

团结实现物体延时出现的方法