private static Instance instance = null;
public static Instance GetInstance()
{
if (instance == null) {
GameObject g = new GameObject("Instance");
instance = g.AddComponent<Instance>();
DontDestroyOnLoad(g);
}
return instance;
}
实例了一个GameObject并挂上这个脚本的组件
这个GameObject不随场景的更替而销毁