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>
发表评论?

0 条评论。

发表评论


注意 - 你可以用以下 HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>