📜  如何统一创建单例 - C# 代码示例

📅  最后修改于: 2022-03-11 14:48:45.749000             🧑  作者: Mango

代码示例2
public class SomeClass : MonoBehaviour {
    private static SomeClass _instance;

    public static SomeClass Instance { get { return _instance; } }


    private void Awake()
    {
        if (_instance != null && _instance != this)
        {
            Destroy(this.gameObject);
        } else {
            _instance = this;
              DontDestroyOnLoad(gameObject);
        }
    }
}