Search Unity

Unity 5.3- SceneManager

Discussion in 'Scripting' started by Nikola310, Dec 10, 2015.

  1. Nikola310

    Nikola310

    Joined:
    Oct 24, 2015
    Posts:
    35
    I've just upgraded to Unity 5.3, and my scripts aren't working, because Application.LoadLevel or Application.loadedLevel aren't a thing anymore (I think). How do I use SceneManager?
    I need 2 different SceneManager lines of code (C#):
    -One that's the same as Application.LoadLevel(Application.loadedLevel);
    -One that's the same as Application.LoadLevel("MainMenu");
    TY in advance.
     
  2. Jordi-Bonastre

    Jordi-Bonastre

    Unity Technologies

    Joined:
    Jul 6, 2015
    Posts:
    102
  3. Nikola310

    Nikola310

    Joined:
    Oct 24, 2015
    Posts:
    35
    Uh,where do I put them?
    Here is my Death Menu Script:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class DeathMenu : MonoBehaviour
    5. {
    6.     void Start ()
    7.     {
    8.        
    9.     }
    10.     public void RestartGame()
    11.     {
    12.         Application.LoadLevel (Application.loadedLevel);
    13.        
    14.     }
    15.    
    16.     public void QuitToMain()
    17.     {
    18.         Application.LoadLevel ("MainMenu");
    19.     }
    20. }
    21.  
    Here's my Main Menu script:
    Code (JavaScript):
    1. #pragma strict
    2.  
    3. var music : AudioListener;
    4.  
    5. function QuitGame ()
    6. {
    7.     Debug.Log ("Game is exiting..");
    8.     Application.Quit ();
    9. }
    10.  
    11. function StartGame (level : String)
    12. {
    13.      Application.LoadLevel (level);
    14. }
    15.  
    16. function SetGameVolume (vol : float)
    17. {
    18.     music.volume = vol;
    19. }
    20.  
    And here is my PauseMenu script:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class PauseScript : MonoBehaviour {
    5.  
    6.     public GameObject PauseUI;
    7.     private bool paused = false;
    8.  
    9.     void Start ()
    10.     {
    11.         PauseUI.SetActive (false);
    12.  
    13.     }
    14.  
    15.     public void Restart()
    16.     {
    17.         Application.LoadLevel (Application.loadedLevel);
    18.     }
    19.  
    20.     public void Quit()
    21.     {
    22.         Application.Quit ();
    23.     }
    24.  
    25.     public void Resume()
    26.     {
    27.         paused = false;
    28.     }
    29.  
    30.  
    31.     void Update ()
    32.     {
    33.         if(Input.GetKeyDown("escape"))
    34.             {
    35.             print ("escape is pressed");
    36.             paused = !paused;
    37.             }
    38.  
    39.         if(paused)
    40.         {
    41.             PauseUI.SetActive(true);
    42.             Time.timeScale = 0;
    43.  
    44.         }
    45.  
    46.         if(!paused)
    47.         {
    48.             PauseUI.SetActive(false);
    49.             Time.timeScale = 1;
    50.         }
    51.  
    52.     }
    53.  
    54. }
    55.  
     
  4. Jordi-Bonastre

    Jordi-Bonastre

    Unity Technologies

    Joined:
    Jul 6, 2015
    Posts:
    102
    First of all, include this:
    Code (CSharp):
    1. using UnityEngine.SceneManagement;
    And change
    Code (CSharp):
    1. [URL='http://unity3d.com/support/documentation/ScriptReference/30_search.html?q=Application']Application[/URL].[URL='http://unity3d.com/support/documentation/ScriptReference/30_search.html?q=LoadLevel']LoadLevel[/URL]([URL='http://unity3d.com/support/documentation/ScriptReference/30_search.html?q=Application']Application[/URL].[URL='http://unity3d.com/support/documentation/ScriptReference/30_search.html?q=loadedLevel']loadedLevel[/URL]);
    to
    Code (CSharp):
    1. SceneManager.LoadScene(Application.loadedLevel);
    Code (CSharp):
    1. Application[/URL].[URL='http://unity3d.com/support/documentation/ScriptReference/30_search.html?q=LoadLevel']LoadLevel[/URL]("MainMenu");
    to
    Code (CSharp):
    1. SceneManager.LoadScene("MainMenu");
     
  5. Nikola310

    Nikola310

    Joined:
    Oct 24, 2015
    Posts:
    35
    Thank you very much :)
     
    Jordi-Bonastre likes this.
  6. TalkingDog

    TalkingDog

    Joined:
    Feb 22, 2013
    Posts:
    20
    Is there a more detailed explanation of using SceneManager? I feel like the documentation pages still leaves me with questions. Like what's the deal with the additive loading mode? When I add a scene can I control the visibility of it? How do I use SceneManager for loading screen situations? When you set a scene to active what does that mean?

    I'm making a kiosk and would either like a better feedback mechanism while loading the other scene or I would like to have all scenes loaded at the beginning and just alternate the visibility of scenes.
     
unityunity