我试图在触发器满足后等待五秒钟,然后在五秒钟后我想要进入下一个场景.问题是一旦触发得到满足,它就会自动进入下一个场景.
我试过了什么
using UnityEngine;
using System.Collections;
public class DestroyerScript : MonoBehavIoUr {
IEnumerator WaitAndDie()
{
yield return new WaitForSeconds(5);
}
void Update()
{
StartCoroutine(WaitAndDie());
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Player")
{
Update();
Application.LoadLevel("GameOverScene");
return;
}
}
}
我也试过了
using UnityEngine;
using System.Collections;
public class DestroyerScript : MonoBehavIoUr {
IEnumerator WaitAndDie()
{
yield return new WaitForSeconds(5);
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Player")
{
StartCoroutine(WaitAndDie());
Application.LoadLevel("GameOverScene");
return;
}
}
}
解决方法:
这应该工作
using UnityEngine;
using System.Collections;
public class DestroyerScript : MonoBehavIoUr {
bool dead;
IEnumerator OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Player")
{
yield return new WaitForSeconds(5);
Application.LoadLevel("GameOverScene");
dead = true;
return dead;
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。