Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Start menu is dissapearing instantly

Discussion in 'Getting Started' started by Yegor42069, Apr 1, 2023.

  1. Yegor42069

    Yegor42069

    Joined:
    Dec 5, 2022
    Posts:
    26
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.SceneManagement;
    5.  
    6. public class StartGame : MonoBehaviour
    7. {
    8.     private void Start()
    9.     {
    10.         SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
    11.     }
    12. }
    13.  
    Ive been working on my game for about a 3 months now and im close to finishing it and i just added my start menu but every time i hit play it disappears and goes to level 1 instantly this i s really frustrating what can i do too fix it.
     
  2. Deleted User

    Deleted User

    Guest

    Start will run as soon as the scene starts. In your code you load the scene straightaway so it will load the +1 index scene when you run it. That's if Start is index 0.

    If your start menu scene has buttons in you'd need to call your SceneManager code within a public method on a chosen gameobject.

    I can also suggest to go into Build Settings and make sure the StartMenuScene is at index 0. You can drag the scene order by holding left mouse.

    The docs say
    Unity builds scenes in the order in which they appear in the list.

    Also make sure they have the tick box active on the left hand side to include them. You can add the start scene by clicking "add open scene" in the build settings with your start menu loaded up.
     
  3. Yegor42069

    Yegor42069

    Joined:
    Dec 5, 2022
    Posts:
    26
    Ok thank you for your help, but i knew that my scene was supposed to be at start index 0 and I just made it a public method but for some reason nothing works I just dont understand why it does this.
     
  4. Deleted User

    Deleted User

    Guest

    I tried learning Timeline and Cinemachine. I created an activation track for a particle effect and it doesn't work. I'm scratching my head too!
     
  5. Yegor42069

    Yegor42069

    Joined:
    Dec 5, 2022
    Posts:
    26
    Never mind i Just found out why it wasnt working I used public void start which instanty started my game so i changed it too public void play game