2017-08-28 4 views
1

Insgesamt gibt es 9 Szenen. Alle sind in "Build Settings" hinzugefügt. 7 Szenen von 9 laden, aber wenn ich versuche, andere zwei Szenen laden sie immer wieder gesagt:Die Szene wird nicht geladen

Szene ‚SceneName‘ konnte nicht geladen werden, da es wurde auf die Build-Einstellungen nicht hinzugefügt oder die AssetBundle hat nicht geladen Um eine Szene zu den Erstellungseinstellungen hinzuzufügen, verwenden Sie das Menü Datei-> Erstellungseinstellungen ... UnityEngine.SceneManagement.SceneManager: LoadSceneAsync (String, LoadSceneMode) MoreMountains.CorgiEngine.c__Iterator0: MoveNext() (unter Assets/CorgiEngine/Common/Scripts/Manager/LoadingSceneManager.cs: 88) UnityEngine.MonoBehaviour: StartCoroutine (IEnumerator) MoreMountains.CorgiEngine.LoadingSceneManager: Start() (bei Aktiva/CorgiEngine/Common/Scripts/Manager/LoadingSceneManager.cs: 67)

Here is my "Scene In Build" Image

Ich habe die Szene bereits im Szenenmanager hinzugefügt, aber sie zeigt diesen Fehler weiterhin an. Ich habe so viel versucht. Bitte helfen Sie mir, das Problem zu lösen. Hier ist meine "LoadingSceneManager" Skript:

using UnityEngine; 
using UnityEngine.UI; 
using System.Collections; 
using System.Collections.Generic; 
using MoreMountains.Tools; 
using UnityEngine.SceneManagement; 

namespace MoreMountains.CorgiEngine 
{ 
public class LoadingSceneManager : MonoBehaviour 
{ 
    [Header("Binding")] 
    /// The name of the scene to load while the actual target scene is 
    loading (usually a loading screen) 
    public static string LoadingScreenSceneName="LoadingScreen"; 

    [Header("GameObjects")] 
    /// the text object where you want the loading message to be displayed 
    public Text LoadingText; 
    /// the canvas group containing the progress bar 
    public CanvasGroup LoadingProgressBar; 
    /// the canvas group containing the animation 
    public CanvasGroup LoadingAnimation; 
    /// the canvas group containing the animation to play when loading is complete 
    public CanvasGroup LoadingCompleteAnimation; 

    [Header("Time")] 
    /// the duration (in seconds) of the initial fade in 
    public float StartFadeDuration=0.2f; 
    /// the speed of the progress bar 
    public float ProgressBarSpeed=2f; 
    /// the duration (in seconds) of the load complete fade out 
    public float ExitFadeDuration=0.2f; 
    /// the delay (in seconds) before leaving the scene when complete 
    public float LoadCompleteDelay=0.5f; 

    protected AsyncOperation _asyncOperation; 
    protected static string _sceneToLoad = ""; 
    protected float _fadeDuration = 0.5f; 
    protected float _fillTarget=0f; 
    protected string _loadingTextValue; 

    /// <summary> 
    /// Call this static method to load a scene from anywhere 
    /// </summary> 
    /// <param name="sceneToLoad">Level name.</param> 
    public static void LoadScene(string sceneToLoad) 
    {  
     _sceneToLoad = sceneToLoad;     
     Application.backgroundLoadingPriority = ThreadPriority.High; 
     if (LoadingScreenSceneName!=null) 
     { 
      SceneManager.LoadScene(LoadingScreenSceneName); 
     } 
    } 

    /// <summary> 
    /// On Start(), we start loading the new level asynchronously 
    /// </summary> 
    protected virtual void Start() 
    { 
     _loadingTextValue=LoadingText.text; 
     if (_sceneToLoad != "") 
     { 
      StartCoroutine(LoadAsynchronously()); 
     } 
    } 

    /// <summary> 
    /// Every frame, we fill the bar smoothly according to loading progress 
    /// </summary> 
    protected virtual void Update() 
    { 
     LoadingProgressBar.GetComponent<Image>().fillAmount = MMMaths.Approach(LoadingProgressBar.GetComponent<Image>().fillAmount,_fillTarget,Time.deltaTime*ProgressBarSpeed); 
    } 

    /// <summary> 
    /// Loads the scene to load asynchronously. 
    /// </summary> 
    protected virtual IEnumerator LoadAsynchronously() 
    { 
     // we setup our various visual elements 
     LoadingSetup(); 

     // we start loading the scene 
     _asyncOperation = SceneManager.LoadSceneAsync(_sceneToLoad,LoadSceneMode.Single); 
     _asyncOperation.allowSceneActivation = false; 

     // while the scene loads, we assign its progress to a target that we'll use to fill the progress bar smoothly 
     while (_asyncOperation.progress < 0.9f) 
     { 
      _fillTarget = _asyncOperation.progress; 
      yield return null; 
     } 
     // when the load is close to the end (it'll never reach it), we set it to 100% 
     _fillTarget = 1f; 

     // we wait for the bar to be visually filled to continue 
     while (LoadingProgressBar.GetComponent<Image>().fillAmount != _fillTarget) 
     { 
      yield return null; 
     } 

     // the load is now complete, we replace the bar with the complete animation 
     LoadingComplete(); 
     yield return new WaitForSeconds(LoadCompleteDelay); 

     // we fade to black 
     GUIManager.Instance.FaderOn(true,ExitFadeDuration); 
     yield return new WaitForSeconds(ExitFadeDuration); 

     // we switch to the new scene 
     _asyncOperation.allowSceneActivation = true; 
    } 

    /// <summary> 
    /// Sets up all visual elements, fades from black at the start 
    /// </summary> 
    protected virtual void LoadingSetup() 
    { 
     GUIManager.Instance.Fader.gameObject.SetActive(true); 
     GUIManager.Instance.Fader.GetComponent<Image>().color=new Color(0,0,0,1f); 
     GUIManager.Instance.FaderOn(false,ExitFadeDuration); 

     LoadingCompleteAnimation.alpha=0; 
     LoadingProgressBar.GetComponent<Image>().fillAmount = 0f; 
     LoadingText.text = _loadingTextValue; 

    } 

    /// <summary> 
    /// Triggered when the actual loading is done, replaces the progress bar with the complete animation 
    /// </summary> 
    protected virtual void LoadingComplete() 
    { 
     LoadingCompleteAnimation.gameObject.SetActive(true); 
     StartCoroutine(MMFade.FadeCanvasGroup(LoadingProgressBar,0.1f,0f)); 
     StartCoroutine(MMFade.FadeCanvasGroup(LoadingAnimation,0.1f,0f)); 
     StartCoroutine(MMFade.FadeCanvasGroup(LoadingCompleteAnimation,0.1f,1f)); 

    } 
} 

}

+1

Was meinst du mit "Ich habe die Szene bereits im Szenenmanager hinzugefügt"? Sprechen Sie über die Build-Einstellungen? (Menü 'Datei'>' Build-Einstellungen'). Sind Sie sicher, dass der Name der Szene, die Sie laden möchten, ** genau ** der Name der Szene in den Build-Einstellungen ist? – Hellium

+0

Nur eine Randbemerkung zu Stil, Sie müssen Ihre privaten/geschützten Variablen nicht mit Unterstrichen in C# voranstellen. Sie können 'these.sceneToLoad = sceneToLoad' anstelle der Unterstreichungssyntax verwenden. – Soviut

+0

@Hellium ja ich spreche über die Build-Einstellungen, alle Szenen, die ich geladen werden möchten, sind in Build-Einstellungen mit korrektem Namen, aber immer noch zeigt es den Fehler – Farooq

Antwort

3

Haben Sie hinzugefügt, um Ihre Szene, die Sie versuchen, in die Buildeinstellungen "Szenen in Build" Section zu laden? Dies ist erforderlich, um mit dem Szenenmanager zu einer beliebigen Szene in Ihrem Projekt zu wechseln.

enter image description here

+0

ja ich habe bereits alle Szenen in "Scene In Build" mit korrektem Namen hinzugefügt – Farooq

0

GO File-> und Build-Einstellung sicherstellen, dass Sie in der Box alle Szene haben. enter image description here

0

oder Sie können vielmehr durch ihre Indexwerte seine viel einfacher Ansatz verwenden, dann Zeichenfolge mit

SceneManager.LoadScene (0);

und fügen Sie dann alle jene Szene durch Öffnen Build Fenster Einstellung

0

Es ist aussehen wie Sie versuchen, mit dem Namen Szene zu laden: ‚SceneName‘.

  1. Überprüfen Sie, ob die Funktionsparameter richtig eingestellt sind.
  2. Versuchen Sie, problematische Szenen mit Indizes anstelle von Namen zu laden.
0

Bitte überprüfen Sie Ihre Funktion "LoadScene".

Ich bin mir nicht sicher, was genau Problem ist, aber von Ihren Protokollen ist das Problem in "LoadScene" -Funktion.