Forum begins after the advertisement:


[Part 9] DestroyInMainMenu script doesnt work

Home Forums Video Game Tutorial Series Creating a Metroidvania in Unity [Part 9] DestroyInMainMenu script doesnt work

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #12253
    Kenura
    Level 10
    Former Patron
    Helpful?
    Up
    0
    ::

    the script in the part 9 video to destroy the singleton prefabs when the player exits to main menu doesnt work

    #12262
    Terence
    Level 30
    Keymaster
    Helpful?
    Up
    0
    ::

    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):

    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);
            }
        }
    }
    #12263
    Kenura
    Level 10
    Former Patron
    Helpful?
    Up
    0
    ::

    That fixed it, i forgot that i added another scene before the menu.

    Thank you!

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: