2015-12-09 13 views
14

Unity 5.3 önce benBirim 5.3 Güncel seviye nasıl yüklenir?

Application.LoadLevel(Application.loadedLevel); 

yapabileceğini Ama şimdi SceneManager ile garip bir şey. Belgeleri okudum ama hiçbir şey. Mevcut sahneyi nasıl alıp yüklerim (Unity 5.3f4)?

Teşekkürler!

+0

veya 'SceneManager.LoadScene (SceneManager.GetActiveScene() buildIndex.) el yazısını ve adını r seçin;' – tim

cevap

20

Kullanım yeni SceneManager ve ad 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); 
    } 
} 
-3

dahil etmeye özen benim C# örnek :) akılda tutmak gerekir, ben aynı problem vardı ve şimdi onunla anladım göre lütfen sahne, projenizin inşa ayarlarına dahil edilmelidir;) , bunun yeni kutularda başkalarına yardımcı olacağını umuyoruz) Şerefe :)
PS denetçisindeki Düğmenizin Bu komut dosyasını ekleyin ve bu işlevin :)

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

bu gidiyor buggy, sahne yöneticisi ile yüklerseniz önceden yüklenmiş tüm nesneler kalacaktır – GameDeveloper

0
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");** 
    } 
}