单例模式

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Script_04_05 : MonoBehaviour
{

    public static Script_04_05 instance;

    static Script_04_05()
    {
        GameObject go = new GameObject("#zyf#");
        DontDestroyOnLoad(go);
        go.AddComponent<Script_04_05>();
    }

    public void DoSomeThing()
    {
        Debug.Log("zyf DoSomeThing");
    }

    private void Start()
    {
        Debug.Log("Start");
    }

}
posted @ 2022-02-21 17:12  小帆敲代码  阅读(12)  评论(0编辑  收藏  举报