Unity不销毁的单例写法
// Use this for initialization
void Awake()
{
if (instance == null)
{
instance = this;
DontDestroyOnLoad(this);
name = "UserManager";
}
else if (this != instance)
{
string sceneName = SceneManager.GetActiveScene().name;
Debug.Log("删除场景" + sceneName + "的" + name);
Destroy(gameObject);
}
}

文档信息
- 本文作者:康
- 本文链接:https://startnight.github.io/2021/09/07/Unity%E4%B8%8D%E9%94%80%E6%AF%81%E7%9A%84%E5%8D%95%E4%BE%8B/
- 版权声明:自由转载-非商用-非衍生-保持署名(创意共享3.0许可证)
