I have a button in my Unity2D game that the user can click and the scene will start over. On my button, I have a script attached with this code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class Restart : MonoBehaviour
{
public void PlayAgain()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
Debug.Log("Play Again Works");
}
}
I know that the button is working and the Play Again function is working because the Debug.Log is working. However, when I click the button the scene doesn’t restart. When I click the button, in the Unity hierarchy, next to the scene name it very briefly shows “(not loaded)”. The scene is in the build settings so that shouldn’t be a problem. Does anyone know what could be causing this?
I screen recorded what is going on click the link below to see. If you look in the hierarchy, you can see sometimes it is saying “not loaded” next to the scene name. Also, you can look in the console to see the debug.log pop up each time I click the button. Thank you so much for your help.