我有两个场景"GamePlay“和"GameUI”。
我额外地加载了GameUI和GamePlay
void Awake () {
if (!instance) {
instance = this;
} else {
Destroy(this.gameObject) ;
}
SceneManager.LoadScene ("GameUI", LoadSceneMode.Additive);
DontDestroyOnLoad(this.gameObject);
}现在,当我重新加载"GamePlay“场景时
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);如何防止重新加载"GameUI“场景?
发布于 2017-07-31 08:12:24
您可以添加一个附加到MonoBehaviour的GameUI,该GameUI包含一个静态bool,它指示对象是否存在。使用下面的脚本使整个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是否已经在场景中。
https://stackoverflow.com/questions/45400703
复制相似问题