Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
avatar image
1
Question by Cisxia_99 · Oct 04, 2017 at 07:16 AM · scripting beginnertutorialsload scene

how to load a previous scene after a "restart" scene?

help, i want to make it that, after the current scene it goes to the next scene and so forth, and when the player loses, it goes to a "restart" scene and should go back the scene where he lost. eg. stage1 -> stage2 -> stage3 ->"loses" -> "restart" scene -> should go back to the stage3 while using only 1 "restart" scene.. and same goes if the player if they lose at stage 2 or 1 and will still go back to the previous scene or stage..

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
2
Best Answer

Answer by Bilelmnasser · Oct 04, 2017 at 08:45 AM

hi , the theory is simple as this : alt text place this in your first scene on active gameobject, call to load new scene

 MasterSceneManager .Instance.LoadNext(string scene)

and to load previous scene

 MasterSceneManager .Instance.LoadPrevious();

Full Code :

   using UnityEngine;
     using System.Collections;
     using UnityEngine.SceneManagement;
     public class MasterSceneManager : MonoBehaviour {
       public  static Stack previouslevel;
         public static MasterSceneManager Instance;
         private void Awake()
         {
             DontDestroyOnLoad( this );
             Instance = this;
             previouslevel = new Stack( );
           
         }
     
     
         public void LoadPrevious()
         {
             //just pop last scene
             if ( previouslevel.Count > 0 )
                 SceneManager.LoadScene( previouslevel.Pop( ).ToString( ) );
             else
                 Debug.Log( "no previous scene in the stack" );
     
         }
         public void LoadNext(string scene)
         {
     
     
             // check if the current scene is not restart scene // we dont want restart or Loses scene in our stack at all 
 //in this if statement add all scene we don't need to track back !!
             if ( SceneManager.GetActiveScene( ).name != "loading"  ||  SceneManager.GetActiveScene( ).name != "loses" )
             {
                 
                     previouslevel.Push( SceneManager.GetActiveScene( ).name );
             }
             else
                 Debug.Log( "scene restart is not added to stack " );
     
             //always load the wanted scene
             SceneManager.LoadScene( scene );
     
         }
         
     }
     

  



Edit ( @Cisxia_99 here is the example of use) : Package Included as an attachement Zip file in this Answer :

  1. create Unity new project

  2. import the package

  3. add all scenes to Build Setting

  4. Open scene 1 and run

Master Scene Package Example


masterscenemanager.zip (24.8 kB)
stack.png (18.3 kB)
Comment
Add comment · Show 6 · 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 Cisxia_99 · Oct 04, 2017 at 11:11 AM 0
Share

i did got the logic, thank yo very much, one last question... where should i put this script?? do i have to put it on every scene?? or should i make a gameobject in every scene and reuse the script per scene? im sorry, im still new to scripting and techniques in using scripts. >.<)

the scene flow is: Start>DemoStage>Stage1>Stage2 (if lose go restart scene else go next stage)...

avatar image Bilelmnasser · Oct 04, 2017 at 11:47 AM 2
Share

Just you put this only in your first scene, attached to active game object .

avatar image Cisxia_99 Bilelmnasser · Oct 04, 2017 at 12:02 PM 1
Share

thank you very much again, i forgot to include that once they enter the lose scene, they will have to press a button and that button will trigger to restart the previous scene... ><)/ im sorry.. alt text

untitled.png (101.3 kB)
avatar image Bilelmnasser Cisxia_99 · Oct 04, 2017 at 12:11 PM 2
Share

yes , when they click the restart button call

  $$anonymous$$asterScene$$anonymous$$anager .Instance.LoadPrevious();
 
Show more comments
avatar image
0

Answer by Remingsworth · Oct 04, 2017 at 08:33 AM

Use Application.LoadLevel("name of scene"); There are many ways to handle progressing/restarting. For instance, make a level manager object with a script on it. You could have DontDestroyOnLoad() in the game manager script or you could manually place the game manager object in each scene. For the script on the game manager object, if you're on level 1... If(playerWinsLevel1 == true){Application.LoadLevel("Level2");} If(playerLosesLevel1 == true){Application.LoadLevel("Level1");}. This is just a messy example but it will work and should be easy if you're new to scripting. Here's the api for the methods I mentioned. https://docs.unity3d.com/ScriptReference/Application.LoadLevel.html and https://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html

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

76 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

Related Questions

Load new scene on object click 1 Answer

How to get AI ( Boots ) 1 Answer

Need some pointers towards basics. 0 Answers

Can anyone give the help me with the full Movearound.javascript? 0 Answers

Tutorials Don't work. 1 Answer


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