我在B站跟着视频
[Unity编程]这大概是最好理解的UI框架了吧
搭建UI框架之后,在Main场景和Start场景切换出现了问题,当我从Main场景退回到Start场景之后,再次点击按钮试图进入Main场景时报了这个错误,并且无法加载MainPanel,这个问题真的卡了我非常久。
之后我在stackoverflow里面找到了解决办法,
大致就是全局管理器GameRoot的单例模式出了些问题
参考这部分GameRoot的原代码:
private void Awake()
{
if (Instance == null)
Instance = this;
else
Destroy(gameObject);
Instance = this;
SceneSystem = new SceneSystem();
DontDestroyOnLoad(gameObject);
}
修改过后:
private void Awake()
{
if (Instance != null && Instance != this)
{
Destroy(this.gameObject);
}
else
{
Instance = this;
}
SceneSystem = new SceneSystem();
DontDestroyOnLoad(this.gameObject);
}