I’m trying to create a script that will, after a delay, swap the scene. Right now, the player character will move into the end point which will run a script that activates an animation with a level complete screen, and I’m trying to make it so that a few seconds after this run (so that the player can look at it for a second) the next scene will start. The script for the scene swap is in a completely different script from the one used to start the animation, so I have no clue how to call for it to be used in the Game Manager. Additionally, I’m also unsure of how to properly delay the script.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class GameManager : MonoBehaviour
{
bool gameHasEnded = false;
public float restartDelay = 1f;
public GameObject completeLevelUI;
// Start is called before the first frame update
public void EndGame ()
{
if (gameHasEnded == false)
{
gameHasEnded = true;
Debug.Log("GAME OVER");
Invoke("Restart", restartDelay);
}
}
void Restart()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
public void CompleteLevel()
{
completeLevelUI.SetActive(true);
}
}
//This is the Game Mananger
//This is the next scene script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class NextLevel : MonoBehaviour
{
// Start is called before the first frame update
public void LoadNextLevel()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
}
}