4
我试图等到触发器满足后五秒钟,然后在五秒钟后,我想去下一个场景。问题是,一旦触发器被满足,它会自动进入下一个场景。如何在激活触发器后等待5秒钟?
我已经试过
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;
}
}
}