2017-07-30 81 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是否已在现场。