月度存档: 7 月 2019

unity MonoBehaviour也可以实现单例

<code>public class GameLaunch:MonoBehaviour
{
    
    public static GameLaunch _instance;

    public static GameLaunch instance
    {
        get{
            if (_instance == null)
            {
                GameObject go = new GameObject("GameLaunch");
                DontDestroyOnLoad(go);
                _instance = go.AddComponent&lt;GameLaunch>();
            }
            return _instance;
        }
    }
}</code>