Unity 5.3 How to load current level?

后端 未结 4 702
暗喜
暗喜 2020-12-11 01:14

before Unity 5.3, I could do

Application.LoadLevel(Application.loadedLevel);

But now it\'s something weird with SceneManager. I\'ve read d

相关标签:
4条回答
  • 2020-12-11 01:20

    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);
        }
    }
    
    0 讨论(0)
  • 2020-12-11 01:21

    it's my C# example:) i had the same problem and now i have figured out with it, you must keep in mind that your scene must be included to the build settings of your project;) hope this will help others with new canges in it) Cheers:)
    P.S. Add this script to your button in inspector and choose you r script and name of this function:)

    using UnityEngine;
    using System.Collections;
    using UnityEngine.SceneManagement;
    
    public class start_new_game : MonoBehaviour {
    
    // Use this for initialization
    void Start () {
    
    }
    
    // Update is called once per frame
    public void Update () {
    
    }
    public void OnMouseDown()
    {
            SceneManager.LoadScene(0);
     }
    
    }
    
    0 讨论(0)
  • 2020-12-11 01:37

    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.

    0 讨论(0)
  • 2020-12-11 01:38
    using UnityEngine;    
    using UnityEngine.UI;   
    using System;   
    using System.Collections;  
    **using UnityEngine.SceneManagement;**
    
    public class UIManager : MonoBehaviour{
    
    public void OnRoomJoin(BaseEvent e)
        {   
    
            // Remove SFS2X listners and re-enable interface before moving to the main game scene
            //Reset();
    
            // Goto the main game scene
            **SceneManager.LoadScene(1);**
    //     **SceneManager.LoadScene("main");**  
        }   
    }
    
    0 讨论(0)
提交回复
热议问题