Load scene after time
I am trying to load from the 'gameover' scene to the 'game result' scene. It wont work. What i want it to be is when the game is gameover, it will pop out a gameover picture. then after 5 seconds, it will load to the game result scene. everything works fine until the loading to game result scene part. is there any solution to solve?
 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 using UnityEngine.SceneManagement;
 
 public class gameTimer : MonoBehaviour
 {
     public float eggyTimer = 30;
     public Text timerText;
     private bool timerIsActive = true;
     private bool sceneTimerIsActive = true;
     GameObject[] gameOver;
     public float sceneTimer = 5;
     
     // Use this for initialization
     void Start()
     {
         timerText = GetComponent<Text>();
 
         Time.timeScale = 1;
         gameOver = GameObject.FindGameObjectsWithTag("showOnGMO");
         hideGMO();
     }
 
     // Update is called once per frame
     void Update()
     {
         if (timerIsActive)
         {
             eggyTimer -= Time.deltaTime;
             timerText.text = eggyTimer.ToString("f0");
             
             print(eggyTimer);
 
             if (eggyTimer <= 0)
             {
                 eggyTimer = 0;
                 timerIsActive = false;
 
                 print("GAME OVER");
 
                  if (Time.timeScale == 1)
                  {
                      Time.timeScale = 0;
                      showGMO();
 
                     //load scene time > new scene
                     if (sceneTimerIsActive)
                     {
                         sceneTimer -= Time.deltaTime;
                         print(sceneTimer);
                         if (sceneTimer <= 0)
                         {
                             sceneTimer = 0;
                             sceneTimerIsActive = false;
                             SceneManager.LoadScene("GameResult");
                         }
                     }
 
                 }
                  else if (Time.timeScale == 0)
                  {
                      Time.timeScale = 1;
                      hideGMO();
                  }
             }
         }
     }
 
 
     public void showGMO()
     {
         foreach (GameObject h in gameOver)
         {
             h.SetActive(true);
         }
     }
 
 
     public void hideGMO()
     {
         foreach (GameObject h in gameOver)
         {
             h.SetActive(false);
         }
     }
 }
Answer by DoomSlayer1995 · Sep 15, 2017 at 01:00 AM
I would do this:
 void GoToScene(){
 SceneManager.LoadScene("MyScene");
 }
 float timeToLoadScene = 10;
 Invoke("GoToScene", timeToLoadScene);
The invoke will execute the function if you call it, in the time you say. You can place it in any moment, like after a collision.
Your answer
 
 
             Follow this Question
Related Questions
Problem setting Time.timeScale to 1 after being set to 0 0 Answers
How do I do math in unity.(timer/60 and timer%60) 1 Answer
Milliseconds Timer Question 1 Answer
Slow Motion Issues! 1 Answer
Using Time.deltaTime as a Timer 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                