2017-07-30 77 views
1

重裝UIScene我有2個場景「遊戲」和「GameUI」。刷新GameScene沒有Unity3d

我加載GameUI相加與遊戲

void Awake() { 
    if (!instance) { 
     instance = this; 
    } else { 
     Destroy(this.gameObject) ; 
    } 

    SceneManager.LoadScene ("GameUI", LoadSceneMode.Additive); 
    DontDestroyOnLoad(this.gameObject); 
} 

現在,當我重新加載使用

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

如何防止重載 「GameUI」 場景中的 「遊戲」 的場景?

回答

1

您可以添加附加到其中包含一個靜態布爾表示,如果對象存在的GameUI的MonoBehaviour。讓你的整個UI的場景一個對象的孩子與下面的腳本。

public class UIExistance : MonoBehaviour 
{ 
    public static bool Exists { get; private set; } 

    void Awake() 
    { 
     DontDestroyOnLoad(transform.gameObject); 
     UIExistance.Exists = true; 
    } 

    void OnDestroy() 
    { 
     UIExistance.Exists = false; 
    } 
} 

當你在你的貼Awake方法,你可以用if(!UIExistance.Exists)檢查UI是否已在現場。