Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unity 5.3 How to load current level?

before Unity 5.3, I could do

Application.LoadLevel(Application.loadedLevel);

But now it's something weird with SceneManager. I've read documentation but nothing. How do I get the current scene and load it (Unity 5.3f4)?

Thanks!

like image 576
NakkyGraphics Avatar asked Dec 09 '15 04:12

NakkyGraphics


People also ask

How do you load current scene in unity?

Another way for loading current scene with SceneMamager is Something Like this : SceneManager. LoadScene(SceneManager. GetActiveScene().

How do I go back to previous scene in unity?

Whenever you want to change scenes you call LoadScene and pass in the name of the scene, which will then add it to the history in addition to changing scenes. Whenever you want to go back to the previous scene you call PreviousScene.


2 Answers

Use the new SceneManager and make sure you include the namespace UnityEngine.SceneManagement

using UnityEngine.SceneManagement;

public class Example
{
    public void ReloadCurrentScene()
    {
        // get the current scene name 
        string sceneName = SceneManager.GetActiveScene().name;

        // load the same scene
        SceneManager.LoadScene(sceneName,LoadSceneMode.Single);
    }
}
like image 154
JeanLuc Avatar answered Oct 08 '22 09:10

JeanLuc


Another way for loading current scene with SceneMamager is Something Like this :

SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);

be sure that you have include SceneManager in your script.

like image 41
MBehtemam Avatar answered Oct 08 '22 07:10

MBehtemam