纳金网

标题: 临时关闭脚本的原理 [打印本页]

作者: 王者再临    时间: 2015-9-30 01:22
标题: 临时关闭脚本的原理

可以说协程是一个至关重要的功能,大部分牵涉到过程和延迟处理的时候都需要用到,下面是一个临时关闭脚本的原理代码:


void OnTriggerEnter(Collider other)
{
if(other.gameObject.name != "Player") return; //skips the rest of the function if something else entered the trigger besides what we want to actually trigger the event
StartCoroutine(MyCoroutine());
}
IEnumerator MyCoroutine()
{
//disable the desired script here //关闭
yield return new WaitForSeconds(10F);//等待10s
//enable it here//再打开
}





欢迎光临 纳金网 (http://go.narkii.com/club/) Powered by Discuz! X2.5