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
0
Question by importguru88 · Sep 08, 2016 at 08:49 AM · scene-loadinglevelhowlevel load

How do I load previous levels individually in the build settings in unity3d

I have one restart game scene in my build settings. In my code script I have it so goes back to previous scene and it does that. The script is working . I need to do this again with different levels . How do go back to previous level but with others levels ? Here is my script :

 //----------------------------------------------------------------------------------------------------
 // Script describes/processes "Button" element of EasyGUI system
 //----------------------------------------------------------------------------------------------------
 
 #pragma strict
 @script AddComponentMenu ("EGUI/UI_Elements/Button")
 import UnityEngine.SceneManagement;
 
 public class EGUI_Button extends EGUI_Element {}
 
 // List of built-in functionality types
 public enum ButtonAction 
 {
   None,                 // Do nothing
   Custom,                 // Call function (name in callFunction) with parameter for actionRecipient object (this gameObject is default)
   LoadLevel,            // Load level with index/name in parameter
   RestartLevel,          // Restart current level
   ExitGame,               // Close application
   SetQuality,             // Set quality level according to parameter (Fastest, Fast, ... Fantastic)
   DecQuality,             // Decrease quality level 
   IncQuality,             // Increase quality level  
   SetResolution,         // Set screen resolution according to parameter (1024x768, 1920x1080 ... etc)
   OpenURL,                // Open URL specified in parameter
   
   CloseEverything,       // Close/disable whole GUI manager and all related GUI-elements. 
   Resume,                 // Close parent GUI-element and set time-scale to 1
   ShowAnother,            // Show GUI-element specified in actionRecipient
   ShowPrevious,           // Show previous GUI-element
   HideThis,              // Hide parent GUI-element  
   HideThis_ShowAnother,  // Hide parent GUI-element and show window specified in actionRecipient
   HideThis_ShowPrevious, // Hide parent GUI-element and show previous window
   
   SoundSwitch            // Enable/Disable all sounds in the scene
    
 };
 
 
 var onClickAction: ButtonAction;    // Action preset to perform onClick
 var actionRecipient: GameObject;    // Optional link to action recipient object
 var callFunction: String;            // Optional name of custom function to call
 var parameter: String;                // Optional parameter to send/use in the Action
 
 
 //=====================================================================================================
 // Overload parent OnClick function to Perform built-in actions
 function OnClick () 
 {
    super.OnClick();
    PerformAction ();
 }
 
 //----------------------------------------------------------------------------------------------------
 // Perform built-in actions according to selected type (onClickAction)
 function PerformAction () 
 {
    switch (onClickAction)
     {
     
       case ButtonAction.None:
           ;
       break;
       
       
       case ButtonAction.Custom:
            if(!actionRecipient) actionRecipient = gameObject;
            if(parameter.Length > 0) actionRecipient.SendMessage (callFunction, parameter, SendMessageOptions.DontRequireReceiver);
              else actionRecipient.SendMessage (callFunction, SendMessageOptions.DontRequireReceiver);
           break;
             
             
       case ButtonAction.LoadLevel:
           Time.timeScale = 1;
             try
                 SceneManager.LoadScene(int.Parse(parameter));
             catch(error)
                 SceneManager.LoadScene(parameter);
           
           if (SceneManager.GetActiveScene().buildIndex > 0) // if not the first scene load the prvious scene
                 SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex - 4);
             else
                 SceneManager.LoadScene(0);
           break;
       
       
       case ButtonAction.RestartLevel: 
           Time.timeScale = 1;
             SceneManager.LoadScene(SceneManager.GetActiveScene().name);
             break;
      
        
       case ButtonAction.ExitGame: 
          SceneManager.LoadScene(0);
           Application.Quit();
           break; 
 
 
       case ButtonAction.SetQuality: 
             switch (parameter)
             {
                 case "Fastest":
                  QualitySettings.SetQualityLevel(QualityLevel.Fastest);
                 break;
                 
                 case "Fast":
                  QualitySettings.SetQualityLevel(QualityLevel.Fast);
                 break;
                 
                 case "Simple":
                  QualitySettings.SetQualityLevel(QualityLevel.Simple);
                 break;
                 
                 case "Good":
                  QualitySettings.SetQualityLevel(QualityLevel.Good);
                 break;
                 
                 
                 case "Beautiful":
                  QualitySettings.SetQualityLevel(QualityLevel.Beautiful);
                 break;
                 
                 
                 case "Fantastic":
                  QualitySettings.SetQualityLevel(QualityLevel.Fantastic);
                 break;
            }
           break;  
 
 
       case ButtonAction.IncQuality: 
           QualitySettings.IncreaseLevel();
       break; 
           
           
       case ButtonAction.DecQuality: 
           QualitySettings.DecreaseLevel();
           break; 
       
                   
       case ButtonAction.SetResolution: 
          Screen.SetResolution ( int.Parse(parameter.Substring(0,parameter.IndexOf("x"))),  int.Parse(parameter.Substring(parameter.IndexOf("x")+1)), Screen.fullScreen);
           break;
           
           
       case ButtonAction.OpenURL: 
             Application.OpenURL(parameter);
           break;               
       
                  
       case ButtonAction.CloseEverything: 
           GetGUIManager().gameObject.SetActive(false);
           break;                                                                                                                                                                                                                                                                      
        
        
       case ButtonAction.Resume: 
           Time.timeScale = 1;
           transform.parent.gameObject.SendMessage("Disable");
           break; 
 
           
       case ButtonAction.ShowAnother:
             if(actionRecipient) actionRecipient.GetComponent(EGUI_Element).SetActivation(true, transform.parent.gameObject);
           break; 
           
           
       case ButtonAction.ShowPrevious:
            if(senderObject) senderObject.SetActive(true);
         break; 
           
           
       case ButtonAction.HideThis:
           transform.parent.gameObject.SendMessage("Disable");
           break; 
           
           
       case ButtonAction.HideThis_ShowAnother:
             if(actionRecipient) actionRecipient.GetComponent(EGUI_Element).SetActivation(true, transform.parent.gameObject);
             transform.parent.gameObject.SendMessage("Disable");
           break; 
           
           
       case ButtonAction.HideThis_ShowPrevious:
             if(senderObject) senderObject.SetActive(true);
           transform.parent.gameObject.SendMessage("Disable");
           break; 
           
           
       case ButtonAction.SoundSwitch:
             if(actionRecipient) actionRecipient.GetComponent(AudioListener).enabled = !actionRecipient.GetComponent(AudioListener).enabled;
           break; 
           
     }
 }
 
 //----------------------------------------------------------------------------------------------------
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

0 Replies

· Add your reply
  • Sort: 

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

53 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

Related Questions

Classic Resident Evil-style room loading/level streaming? 4 Answers

Predfined Level Generation Procedural vs Scene 1 Answer

Blocking level progression. 1 Answer

while i restart the game,it hangs. why so? 3 Answers

how to load level when your enemy health gets to 0 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