unity實(shí)現(xiàn)物體延時(shí)出現(xiàn)
本文實(shí)例為大家分享了unity實(shí)現(xiàn)物體延時(shí)出現(xiàn)的具體代碼,供大家參考,具體內(nèi)容如下
新建一個(gè)cube和plane,隱藏cube,腳本掛在plane上。
1. update計(jì)時(shí)器實(shí)現(xiàn)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//一個(gè)隱藏的物體等待t秒后顯示,updata計(jì)時(shí)器實(shí)現(xiàn)
public class activeShow : MonoBehaviour {
public GameObject cube;
public int t;
private float m_timer=0;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
m_timer+=Time.deltaTime;
if(m_timer>5){
cube.SetActive(true);
m_timer=0;
}
}
}
2. invoke實(shí)現(xiàn)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
一個(gè)隱藏的物體等待t秒后顯示,Invoke實(shí)現(xiàn)
public class ShowT : MonoBehaviour {
public GameObject cube;
public int t;//等待時(shí)間
// Use this for initialization
void Start () {
Invoke("ActiveShow", t);
}
// Update is called once per frame
void Update () {
}
public void ActiveShow(){
cube.SetActive(true);
}
}
3. invokeRepeating實(shí)現(xiàn)(這個(gè)是用來湊數(shù)的)
void Start () {
InvokeRepeating("ActiveShow", t,1000);
}
4. 協(xié)程實(shí)現(xiàn)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//一個(gè)隱藏的物體等待t秒后顯示,協(xié)程實(shí)現(xiàn)
public class HideInSeconds : MonoBehaviour {
public GameObject cube;
IEnumerator ie;
// Use this for initialization
void Start () {
ie=waitFourSeconds();
StartCoroutine(ie);
}
// Update is called once per frame
void Update () {
}
IEnumerator waitFourSeconds(){
yield return new WaitForSeconds(4.0f);
cube.SetActive(true);
}
}
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
C#固定大小緩沖區(qū)及使用指針復(fù)制數(shù)據(jù)詳解
這篇文章主要為大家介紹了C#固定大小緩沖區(qū)及使用指針復(fù)制數(shù)據(jù)詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-12-12
解析c#操作excel后關(guān)閉excel.exe的方法
C#和Asp.net下excel進(jìn)程一被打開,有時(shí)就無法關(guān)閉,尤其是website.對關(guān)閉該進(jìn)程有過GC、release等方法,但這些方法并不是在所有情況下均適用2013-07-07
淺析C#?AsyncLocal如何實(shí)現(xiàn)Thread間傳值
這篇文章主要是來和大家一起討論一下C#?AsyncLocal如何實(shí)現(xiàn)Thread間傳值,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-01-01
深入C#任務(wù)管理器中應(yīng)用程序選項(xiàng)隱藏程序本身的方法詳解
本篇文章是對在C#任務(wù)管理器中應(yīng)用程序選項(xiàng)隱藏程序本身的方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-05-05
用C#在本地創(chuàng)建一個(gè)Windows帳戶(DOS命令)
用C#在本地創(chuàng)建一個(gè)Windows帳戶(DOS命令)...2007-03-03

