Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Jstnwrds55 · Dec 25, 2016 at 08:31 AM · restartlevel loadrestart game

Restart level instead of restart to main menu

Hiya guys, I've been following a Devslopes tutorial and I made a pretty basic flappy bird type game and I'm trying to allow restart level and back to main menu at the game over screen. The way my game runs currently is it starts up at the main menu UI then you click play to play. After you lose the game over thing pops up and you can click restart or menu. I have the back to main menu down because I just used the following to reset the scene back to where the main menu pops up.

 int scene = SceneManager.GetActiveScene ().buildIndex;
 SceneManager.LoadScene (scene, LoadSceneMode.Single);

The problem now is that I can't for the life of me figure out how to get my game to reload to the beginning of the level instead of to the very beginning of the scene where the main menu initializes. I was thinking it had something to do with DontDestroyOnLoad or something but I can't find anything on it and I'm at a total loss on what to do. Sorry if it's vague, I tried to explain as briefly as I could but still make sense. I appreciate any help.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by TheGreyRaveen · Dec 25, 2016 at 07:07 PM

If I'm correct you've got your menu and level in one scene. If you want to keep it like that, you can make a boolean for example "loadMainMenu" which is initially true. When you press the restart button loadMainMenu = false and you reload your scene as you currently do via SceneManager.LoadScene(). At the start of the scene it checks whether loadMainMenu is true or false. If it's false it skips loading all of those Main Menu objects and goes straight into the part where you start flying.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image FranGhigli · Jul 12, 2020 at 02:00 PM 0
Share

How would you do something like that? do booleans transfer when scene loading?

avatar image
0

Answer by ISAKUPOLY · Apr 26, 2021 at 03:17 PM

I just found out a way to restart, instead of turning complete to the menu (all in one scene) I just used

 public GameObject MenuGameObject;
 public static int Number = 0;
     
     void Start()
     {
         if(Number == 1)
         {
             MenuGameObject.SetActive(false); // I just disable the MenuUI and some other stuff.
         }
         else
         {
             MenuGameObject.SetActive(true) //and here I enable it, if I want to load the scene normally.
         }
     }
 
     public void LoadMenu()
     {
 Number=0; // 0 to keep it as 0.
 SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
     }
 
     public void Retry()
     {
         Number = 1;
         SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
     }

This worked for me :)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

86 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

error: Assets/scripts/Gamemaneger.cs(27,51): error CS1525: Unexpected symbol `)' 1 Answer

How to add a restart to my 2D game? 0 Answers

Scenes don't repeat themselves after pressing a restart button 1 Answer

One question... 0 Answers

Invoke restart doesn't work 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges