Forum begins after the advertisement:
-
::the script in the part 9 video to destroy the singleton prefabs when the player exits to main menu doesnt work
::Hi Kenura, you have to make sure that the main menu has a build index of 0 (that’s the number beside the scene in the build settings):
If it is not 0, you will have to update the number in your DestroyInMainMenu
script (see highlight below) accordingly.
using UnityEngine;
using UnityEngine.SceneManagement;
public class DestroyWhenInMainMenu : MonoBehaviour
{
// Update is called once per frame
void Update()
{
if(SceneManager.GetActiveScene().buildIndex == 0)
{
Destroy(gameObject);
}
}
}
::That fixed it, i forgot that i added another scene before the menu.
Thank you!
Advertisement below: