I am trying to wait five seconds after the trigger is met then after the five seconds is up i want to go to the next scene. The problem is that once the trigger is met the it automatically goes to the next scene.
What I have tried
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;
}
}
}
I have also tried
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;
}
}
}
Only call Application.LoadLevel
after yield return
:).
IEnumerator WaitAndDie()
{
yield return new WaitForSeconds(5);
Application.LoadLevel("GameOverScene");
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Player")
{
StartCoroutine(WaitAndDie());
return;
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With