I want that when the level of my test game ends you go back to main menu but after like 3 to 5 seconds this is the part i want to delay:
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag ("Pick it"))
{
other.gameObject.SetActive(false);
count = count + 1;
SetCountText ();
if (count >= 15)
{
winText.text = "Ur Wineh!!";
*The delay goes here*
SceneManager.LoadScene ("Start Menu");
}
You can delay that with a coroutine like so:
private IEnumerator WaitForSceneLoad() {
yield return new WaitForSeconds(3)
SceneManager.Load("A Scene");
}
void OnTriggerEnter(Collider other) {
// Do your things, then:
StartCoroutine(WaitForSceneLoad());
// And done
}
it will continue execution after the yield statement about 3 seconds later and call the SceneManager.
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag (“Pick it”))
{
other.gameObject.SetActive(false);
count = count + 1;
SetCountText ();
if (count >= 15)
{
winText.text = “Ur Wineh!!”;
The delay goes here
// use this for delay
StartCoroutine (WaitToLoadScene());
}
}
IEnumerator WaitToLoadScene(){
yield return new WaitForSeconds (5);
SceneManager.LoadScene (“Start Menu”);
}
@Emperor-Nebur