我试图在触发触发后等待五秒,然后在五秒后我想转到下一个场景。问题是一旦满足触发器,它就会自动转到下一个场景。
我尝试过的
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;
}
}
}
最佳答案
仅在 yield return
之后调用 Application.LoadLevel
:).
IEnumerator WaitAndDie()
{
yield return new WaitForSeconds(5);
Application.LoadLevel("GameOverScene");
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Player")
{
StartCoroutine(WaitAndDie());
return;
}
}
}
关于c# - 触发器激活后如何等待 5 秒?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28404808/